Teen Programmers Unite  
 

 

Return to forum top

Range of numbers in rand() function

Posted by slipknotclown [send private reply] at February 12, 2002, 03:42:40 AM

Ok, can you specify the range of numbers in a rand fucntion? In UK the lottery is played with balls 1-49 so i want to make a random thing that will pick out 6 balls for me, also is it possible to avoid duplicate numbers.

Cheers

Posted by sphinX [send private reply] at February 12, 2002, 06:02:38 AM

(rand()%48 + 1) ????

as for duplicate numbers, just store the 6 balls in an array, say balls[6], then run through the numbers that have been picked so far and check if the new random number is the same as any previous number. if it is, just keep randomizing until you have a unique number

Posted by RedX [send private reply] at February 12, 2002, 06:43:28 AM

Or set up a circular linked list containing the numbers 1-49. Set a pointer to the first element.

Move the pointer a random number to the left. put that number in an array and remove it from the list. Repeat 6 times.

It's a more complex solution, but it gives you 6 different numbers from the first try.

RedX

Posted by vladimir_l [send private reply] at February 12, 2002, 11:21:45 AM

UK lottery sucks , there are programs (illegal ones) that caluculate the chance of ach ball ( from previous draws )and give you the most likely. How can that be illigal ? I have never known anyone who won more than ý0.

-Vlad

Posted by CodeRed [send private reply] at February 12, 2002, 05:18:45 PM

RedX, not necessarily, if it goes all the way around you could get a duplicate. You would have to do something like pointer += rand()%(49-pointer);

Posted by CodeRed [send private reply] at February 12, 2002, 05:19:38 PM

Oh, didn't see that "remove it from the list" part

Posted by RedX [send private reply] at February 13, 2002, 06:16:49 PM

Calculating the chance of a ball from a previous draw? Why would a ball have more chance of coming out if it hasn't been out for many rounds?
Calculating the outcome would require as much information on the physical properties of their lottery equipment, the balls, the way the balls are added and many more. And even with all that data you'll never be 100% sure of the outcome. (The uncertainty priciple comes in to play)

RedX

Posted by taubz [send private reply] at February 13, 2002, 06:36:13 PM

Actually, I think that would be best said that you could never have enough data to be 100% sure of the outcome. Quantum mechanics would come into play too.

Posted by sphinX [send private reply] at February 14, 2002, 12:28:18 AM

did i hear someone cry Heisenburg was a fool? :-)

Posted by RedX [send private reply] at February 14, 2002, 06:46:54 AM

The uncertainty priciple can be used to your advantage. When a teacher states your answers as wrong, you could tell him that by reading them he changed them.
entropy can be used too: If you have to clean your room, tell them about the fact that entropy will always increase and by cleaning your room you'll add to the total amount of chaos in the universe.

Quantum Mechanics: A whole new source of excuses!
RedX

Posted by gian [send private reply] at February 15, 2002, 01:30:31 AM

Unfortunately, I don't think that many of my teachers would go for the uncertainty principle, although I must try it...

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.