# Randomising

**URL:** <https://www.ruby-forum.com/t/randomising/129353>\
**Category:** Ruby\
**Created:** [February 17, 2008, 11:36am UTC](https://www.ruby-forum.com/t/randomising/129353 "2008-02-17T11:36:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![angelojoseph17](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@angelojoseph17](https://www.ruby-forum.com/u/angelojoseph17)\
**Post date:** [February 17, 2008, 11:36am UTC](https://www.ruby-forum.com/t/randomising/129353/1 "2008-02-17T11:36:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![angelojoseph17](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@angelojoseph17](https://www.ruby-forum.com/u/angelojoseph17)\
**Post date:** [February 17, 2008, 3:10pm UTC](https://www.ruby-forum.com/t/randomising/129353/2 "2008-02-17T15:10:37Z")

</div>

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”]

---

<div class="post-metadata">

**Author:** ![angelojoseph17](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@angelojoseph17](https://www.ruby-forum.com/u/angelojoseph17)\
**Post date:** [February 17, 2008, 5:35pm UTC](https://www.ruby-forum.com/t/randomising/129353/3 "2008-02-17T17:35:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![angelojoseph17](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@angelojoseph17](https://www.ruby-forum.com/u/angelojoseph17)\
**Post date:** [February 18, 2008, 12:23pm UTC](https://www.ruby-forum.com/t/randomising/129353/4 "2008-02-18T12:23:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![angelojoseph17](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@angelojoseph17](https://www.ruby-forum.com/u/angelojoseph17)\
**Post date:** [February 18, 2008, 12:12am UTC](https://www.ruby-forum.com/t/randomising/129353/5 "2008-02-18T00:12:41Z")

</div>

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.
