Commit 82c86c12695cd4b6e86199a7c02b21c7c1af66ce

Authored by Dhruv Kapadia
1 parent 0a1c2a36

Removed set from picked_prompt to ensure randomness.

Showing 1 changed file with 4 additions and 4 deletions   Show diff stats
app/models/question.rb
@@ -37,18 +37,18 @@ class Question < ActiveRecord::Base @@ -37,18 +37,18 @@ class Question < ActiveRecord::Base
37 end until @p.active? 37 end until @p.active?
38 return @p 38 return @p
39 end 39 end
40 - memoize :picked_prompt  
41 40
42 def distinct_array_of_choice_ids(rank = 2, only_active = true) 41 def distinct_array_of_choice_ids(rank = 2, only_active = true)
43 @choice_ids = choice_ids 42 @choice_ids = choice_ids
44 @s = @choice_ids.size 43 @s = @choice_ids.size
45 begin 44 begin
46 - first_one, second_one = rand(@s), rand(@s)  
47 - @the_choice_ids = Set.new(@choice_ids.values_at(first_one, second_one)) 45 + index_list = (0...@s).sort_by{rand}
  46 + first_one, second_one = index_list.first, index_list.second
  47 + @the_choice_ids = @choice_ids.values_at(first_one, second_one)
48 # @the_choice_ids << choices.active.first(:order => 'RAND()', :select => 'id').id 48 # @the_choice_ids << choices.active.first(:order => 'RAND()', :select => 'id').id
49 # @the_choice_ids << choices.active.last(:order => 'RAND()', :select => 'id').id 49 # @the_choice_ids << choices.active.last(:order => 'RAND()', :select => 'id').id
50 end until (@the_choice_ids.size == rank) 50 end until (@the_choice_ids.size == rank)
51 - logger.info "set populated and looks like #{@the_choice_ids.inspect}" 51 + logger.info "List populated and looks like #{@the_choice_ids.inspect}"
52 return @the_choice_ids.to_a 52 return @the_choice_ids.to_a
53 end 53 end
54 54