Commit b33fca9dba43af03917a7003da40f5057499fb33
1 parent
3105fb29
Exists in
master
and in
1 other branch
avoiding the database randomization function
Showing
1 changed file
with
5 additions
and
3 deletions
Show diff stats
app/models/question.rb
@@ -34,10 +34,12 @@ class Question < ActiveRecord::Base | @@ -34,10 +34,12 @@ class Question < ActiveRecord::Base | ||
34 | memoize :picked_prompt | 34 | memoize :picked_prompt |
35 | 35 | ||
36 | def distinct_array_of_choice_ids(rank = 2, only_active = true) | 36 | def distinct_array_of_choice_ids(rank = 2, only_active = true) |
37 | + @choice_ids = choice_ids | ||
38 | + @s = @choice_ids.size | ||
37 | begin | 39 | begin |
38 | - @the_choice_ids = Set.new | ||
39 | - @the_choice_ids << choices.active.first(:order => 'RAND()', :select => 'id').id | ||
40 | - @the_choice_ids << choices.active.last(:order => 'RAND()', :select => 'id').id | 40 | + @the_choice_ids = Set.new(@choice_ids.values_at(rand(@s), rand(@s))) |
41 | + # @the_choice_ids << choices.active.first(:order => 'RAND()', :select => 'id').id | ||
42 | + # @the_choice_ids << choices.active.last(:order => 'RAND()', :select => 'id').id | ||
41 | end until @the_choice_ids.size == rank | 43 | end until @the_choice_ids.size == rank |
42 | logger.info "set populated and looks like #{@the_choice_ids.inspect}" | 44 | logger.info "set populated and looks like #{@the_choice_ids.inspect}" |
43 | return @the_choice_ids.to_a | 45 | return @the_choice_ids.to_a |