| Module | Prompt::Random |
| In: |
lib/algorithms/prompt/random.rb
|
| ID | = | 2 | algorithm ID |
Generate count number of random prompts based on question ID and voter ID.
An array of prompts
| question_id<int>: | Generate prompts for this question ID |
| voter_id<int>: | Generate prompts for this voter ID |
| count<int>: | Generate this number of prompts |
# File lib/algorithms/prompt/random.rb, line 15
15: def prompts(question_id, voter_id, count)
16: all_items = items_for_request(question_id)
17: items = []
18: prompt_item_ids = {}
19: # leaks with create/find in req loop
20: Prompt.transaction do
21: count.times do |i|
22: items = all_items.dup if items.length < 2 # ensure we still have items
23: prompt = prompt_for_request(question_id, voter_id, ID)
24: item = items.delete_at(rand(items.length))
25: prompt.items << item << items.delete_at(rand(items.length))
26: redo if bad_prompt?(prompt)
27: prompt_item_ids[prompt.id] = prompt.item_ids
28: end
29: end
30: prompt_item_ids
31: end