Randomising

A

Angelo Joseph

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
 
7

7stud --

Angelo said:
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"]
 
7

7stud --

Robert said:
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.
 
A

Angelo Joseph

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,283
Messages
2,571,407
Members
48,101
Latest member
LinetteDeg

Latest Threads

Top