[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Randomising

angelojoseph803

2/17/2008 10:36:00 AM

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
--
Posted via http://www.ruby-....

4 Answers

7stud --

2/17/2008 2:10:00 PM

0

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"]
--
Posted via http://www.ruby-....

Robert Klemme

2/17/2008 4:31:00 PM

0

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

7stud --

2/17/2008 11:13:00 PM

0

Robert Klemme 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.
--
Posted via http://www.ruby-....

angelojoseph803

2/18/2008 11:24:00 AM

0

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

--
Posted via http://www.ruby-....