![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2008
Posts: 10
Rep Power: 0
![]() |
Patterned returns with Math.random()
I hope I am doing this correct. I am having trouble with a little program I made. It generates lottery numbers in an unconventional way. It is random numbers but the main five numbers repeat exactly every eleventh line. What I mean is, if you give it a command line argument greater than 11 you will see the supposedly randomly generated lines begin to repeat themselves. It is completely bizarre. I suppose that if you want to comment on how bad my coding is you are free to do that as well. It will only help me code better in the future. Please, if anyone can help, it is like a splinter in my mind.
src.zip |
|
|
|
|
|
#2 | |
|
Programming Guru
![]() ![]() |
Re: Patterned returns with Math.random()
You can research this by Googling it. I found a site to start you off.
http://www.particle.kth.se/~lindsey/...aRandNums.html Quote:
setSeed function in Java, to learn more.
__________________
Looking for tough programming challenges? Try participating in Sane's Monthly Algorithms Challenges! Composing Techno is a little side hobby of mine. Techno by DJ Sane. All free for download. |
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: Oct 2007
Posts: 31
Rep Power: 0
![]() |
Re: Patterned returns with Math.random()
Yeah Sane, but thats a pretty bad generator implementation, or something else is going wrong if the repeat beings to occur so soon, you must admit.
Alias |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Mar 2008
Posts: 10
Rep Power: 0
![]() |
Re: Patterned returns with Math.random()
yes, each number in the set {random number 1 - 56, random number 1 - 56, random number 1 - 56, random number 1 - 56, random number 1 - 56} is repeated exactly every 11th set generation however the power ball is always different! That means that it only takes 11*5 random generations before exact repeats occur. I say that because the power ball is generated using a different class entirely and it seems to be unaffected by this weirdness.
|
|
|
|
|
|
#5 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Re: Patterned returns with Math.random()
Usually random() functions can accept seeds (C#, C++ support this, I assume Java does this too), different seeds give different random lists. If you seed the function with Time, you will get a truly random list.
|
|
|
|
|
|
#6 |
|
Programmer
Join Date: Oct 2007
Posts: 31
Rep Power: 0
![]() |
Re: Patterned returns with Math.random()
Personally I would encapsulate the RNG in a class of its own in which it should be constantly generating numbers by the second, then use a method to get the latest generated number - not exactly a solution to your problem but certainly a more appropriate way of returning seemingly random numbers.
Alias |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Oct 2007
Posts: 31
Rep Power: 0
![]() |
Re: Patterned returns with Math.random()
Sorry to smash your glass bubble OpenLoop, there is no truly random number, or set of numbers generated by either C# or Java implementations of RNG's.
Alias |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Mar 2008
Posts: 10
Rep Power: 0
![]() |
Re: Patterned returns with Math.random()
I don't think I need a "truly random" generator. I am not looking to get thousands of unique sets just <=20. I am stuck with 11 unique sets now (not including the power ball)
let me describe my madness. The file src.zip is my program given in the original post. Imagine you selected a random number from a bin I will call 'a', looked at it and then returned it to 'a'. You wrote the number on a card and placed that card in a bin I will call 'b'. Again select randomly from bin 'a', write it on a card and return it. Now compare it to every card in 'b'. If it is the same as another card in 'b', destroy it and repeat the drawing process again from 'a'. Do this process over and over until you have numbers in 'b' equal to one less than the numbers in 'a'. Whatever number is missing from 'b' is the final product! That is the first lotto number you use in the selection process. for every number made this way you place it in an array and call a recursive algorithm to compare every new number to every preexisting element in the set. Do this five times with 'a' and 'b' and then a unique sixth number is made using numbers 1-42 from new sets 'c' and 'd' for the power ball number. Why? WHY!? Well because I am resigned to believe that I will never select even one number that matches the lotto numbers so this way the numbers given are all numbers that were never selected! MWAHAHAHAHAHAAAA!!!!! ahem... sorry. the program compiles and just requires an argument. If you fail to give an argument, fear not for it will ask for and input. |
|
|
|
|
|
#9 |
|
Programming Guru
![]() ![]() |
Re: Patterned returns with Math.random()
The answer is within your reach. Do some searching on the terms given in this thread. Particularly, seeding the random generator. It sounds like you keep seeding the random number generator with bad values, or the same values. Compare your code against that of what you can find through several different sources (IE Google).
__________________
Looking for tough programming challenges? Try participating in Sane's Monthly Algorithms Challenges! Composing Techno is a little side hobby of mine. Techno by DJ Sane. All free for download. |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Mar 2008
Posts: 10
Rep Power: 0
![]() |
Re: Patterned returns with Math.random()
Random rock = new Random(); rock.setSeed(System.nanoTime()); double test = rock.nextDouble(); Yes, I have been playing with setSeed but nothing seems to change the end result. I now believe I have made the mistake in my loops and it has nothing to do with the RNG. It is the only logical conclusion after having tried all the different RNG techniques. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help with assignment code returns no answer | backstabber | C++ | 9 | Dec 21st, 2006 8:46 AM |
| Futurama Returns!!! | Indigno | Coder's Corner Lounge | 27 | Jul 22nd, 2006 3:48 PM |
| Stash returns... Malloc problem? | Soulstorm | C++ | 18 | May 27th, 2006 3:09 AM |
| Function that returns occurances of substring in string. | conbrio | C | 7 | Jul 1st, 2005 7:51 PM |
| Count lenght of list inside list, how to print returns | dezza | Python | 5 | Apr 5th, 2005 1:16 PM |