Dear All,
I am very new to ruby been learning at university for around 6
months. I love it. Anway i am making an app for a project at uni which
involving creating a logoquiz game that has random quizzes. I know there
is something called randomisation but not enough on it. can anyone shed
any light.
I much appreciate this
Angelo
Angelo Joseph wrote:
Dear All,
I am very new to ruby been learning at university for around 6
months. I love it. Anway i am making an app for a project at uni which
involving creating a logoquiz game that has random quizzes. I know there
is something called randomisation but not enough on it. can anyone shed
any light.
I much appreciate this
Angelo
Something like this may be of use to you:
quiz_names = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
random_names = quiz_names.sort_by {|quiz_name| rand(0)}
puts random_names
–output:–
[“b”, “a”, “e”, “c”, “d”]
On 17.02.2008 15:10, 7stud – wrote:
quiz_names = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
random_names = quiz_names.sort_by {|quiz_name| rand(0)}
You do not need the block parameter.
Cheers
robert
Ive basically made 6 quizes which are controllers from models. how do i
randomise them. Is it by making another model and a controller or is it
somewhere else.
Many thanks
Angelo
Robert K. wrote:
On 17.02.2008 15:10, 7stud – wrote:
quiz_names = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
random_names = quiz_names.sort_by {|quiz_name| rand(0)}
You do not need the block parameter.
I know. I also don’t need the parameter for rand(). However, both make
the code easier to follow–especially for someone new.