Permalink
Browse files

fast, correct random prompt picking

  • Loading branch information...
1 parent eaf03aa commit 5883f6f9cc7c9a985ba489c067b560f3898b6b9a Pius Uzamere committed Dec 10, 2009
Showing with 2 additions and 9 deletions.
  1. +0 −1 .gems
  2. +2 −8 app/models/question.rb
View
@@ -8,4 +8,3 @@ justinfrench-formtastic --version '0.2.2' --source gems.github.com
thoughtbot-clearance --version '0.8.2' --source gems.github.com
josevalim-inherited_resources --version '0.9.1' --source gems.github.com
activemerchant --version 1.4.2'
-
@@ -22,20 +22,14 @@ def item_count
end
def picked_prompt
- pc = self.prompts_count < 1 ? 2 : self.prompts_count
begin
- @p = prompts.find(rand(pc-1) + prompts.first.id)
+ @p = prompts.first(:order => 'RANDOM()')
end until @p.active?
return @p
end
-
def picked_prompt_id
- pc = self.prompts_count < 1 ? 2 : self.prompts_count
- begin
- @i = rand(pc-1) + prompts.first.id #try caching this first prompt value at some point
- end until prompts.find(@i).active?
- return @i
+ picked_prompt.id
end
def left_choice_text(prompt = nil)

0 comments on commit 5883f6f

Please sign in to comment.