From 82c86c12695cd4b6e86199a7c02b21c7c1af66ce Mon Sep 17 00:00:00 2001 From: Dhruv Kapadia Date: Fri, 19 Feb 2010 14:02:25 -0500 Subject: [PATCH] Removed set from picked_prompt to ensure randomness. --- app/models/question.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/question.rb b/app/models/question.rb index 3af0005..624a72f 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -37,18 +37,18 @@ class Question < ActiveRecord::Base end until @p.active? return @p end - memoize :picked_prompt def distinct_array_of_choice_ids(rank = 2, only_active = true) @choice_ids = choice_ids @s = @choice_ids.size begin - first_one, second_one = rand(@s), rand(@s) - @the_choice_ids = Set.new(@choice_ids.values_at(first_one, second_one)) + index_list = (0...@s).sort_by{rand} + first_one, second_one = index_list.first, index_list.second + @the_choice_ids = @choice_ids.values_at(first_one, second_one) # @the_choice_ids << choices.active.first(:order => 'RAND()', :select => 'id').id # @the_choice_ids << choices.active.last(:order => 'RAND()', :select => 'id').id end until (@the_choice_ids.size == rank) - logger.info "set populated and looks like #{@the_choice_ids.inspect}" + logger.info "List populated and looks like #{@the_choice_ids.inspect}" return @the_choice_ids.to_a end -- libgit2 0.21.2