
-----------------------------------
anshu402
Sat Feb 16, 2013 11:37 am

Turing Random Numbers
-----------------------------------
i need to create a program where the program generates 6 random numbers between 1-49. however, the numbers cant repeat themsleves. How do i do that? My code:
var ran: array 1..6 of int

for i: 1..6
randint (ran(i),1,49)
put ran(i)

end for

-----------------------------------
Zren
Sat Feb 16, 2013 12:29 pm

RE:Turing Random Numbers
-----------------------------------
There are two ways you do this.

1) Keep rolling your dice until you get a number you haven't used before. You then add that number to the list in your head.

With this method, it's improbably possible to keep rolling numbers you've already rolled for a long time. Each time you do this process, it would take a variant amount of time.

2) Everyone puts their name on a piece of paper and put it in a hat (list). Shuffle them around and pull out the names.

With this, you can limit the shuffling to a finite amount of time (swaps).

-----------------------------------
hamid1455
Sun Feb 17, 2013 1:03 pm

RE:Turing Random Numbers
-----------------------------------
I would say to save the number generated into a variable and then use an if statement to check if the new random number is the same as the one saved in the variable.

-----------------------------------
Raknarg
Sun Feb 17, 2013 2:49 pm

RE:Turing Random Numbers
-----------------------------------
have an array of 1 - 49, make a for loops to go through the program 49 times, each iteration you switch ran(i) with ran (rand.Int (1, 49) then pick the first six numbers.

Simplest solution I can think of.

-----------------------------------
evildaddy911
Sun Feb 17, 2013 2:56 pm

Re: Turing Random Numbers
-----------------------------------
[url=http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle]The algorithm I use for this sort of thing

-----------------------------------
Tony
Mon Feb 18, 2013 1:20 pm

Re: Turing Random Numbers
-----------------------------------


This.

It should be quite natural for most people to figure out how to draw 6 random cards from a deck. Write a number on the card, and you get a list of numbers from a set.
