Computer Science Canada Turing Random Numbers |
Author: | anshu402 [ Sat Feb 16, 2013 11:37 am ] |
Post subject: | 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 |
Author: | Zren [ Sat Feb 16, 2013 12:29 pm ] |
Post subject: | 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). |
Author: | hamid1455 [ Sun Feb 17, 2013 1:03 pm ] |
Post subject: | 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. |
Author: | Raknarg [ Sun Feb 17, 2013 2:49 pm ] |
Post subject: | 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. |
Author: | evildaddy911 [ Sun Feb 17, 2013 2:56 pm ] |
Post subject: | Re: Turing Random Numbers |
The algorithm I use for this sort of thing |
Author: | Tony [ Mon Feb 18, 2013 1:20 pm ] |
Post subject: | Re: Turing Random Numbers |
evildaddy911 @ Sun Feb 17, 2013 2:56 pm wrote:
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. |