|
|
|||||||
| Computers & Information Technologies « Everything related to computers and internet. » |
![]() |
|
|
Share | Thread Tools | Search this Thread |
|
|
#1 |
|
Community Moderator
Last Online: 07-31-2023
Join Date: Oct 2007
Posts: 2,520
Thanks: 3,023
Thanked 2,076 Times in 1,156 Posts
Groans: 7
Groaned at 34 Times in 27 Posts
|
I need to generate random numbers in java, and I need them to be completely evenly distributed(or close to that) specifically I need to generate around 300 numbers between 1 and 100...
math random method is not helping, nor any other traditional random method. the problem is the numbers I get from those methods repeat themselves after a certain time, or that they are not evenly distributed(so I get more than half the numbers below 50 and less than half above it...) any ideas?
__________________
"Loyalty to the country always. Loyalty to the government when it deserves it. " -Mark Twain Last edited by mr_j; 12-16-2011 at 08:40 PM. |
|
|
|
|
|
#2 | |
|
Last Online: 05-30-2013
Join Date: Jan 2008
Posts: 1,788
Thanks: 10,018
Thanked 1,100 Times in 651 Posts
Groans: 1
Groaned at 6 Times in 6 Posts
|
Mathematicaly, that's a random number generator:
x 0 = given, x n+1 = P 1 x n + P 2 (mod N) n = 0,1,2,... The parameters P 1, P 2, and N determine the characteristics of the random number generator, and the choice of x 0 (the seed ) determines the particular sequence of random numbers that is generated. In your case N is 101. 2eza ma beddak twajje3 rasak, try this: Quote:
__________________
|
|
|
|
|
|
|
#3 |
|
Community Moderator
Last Online: 07-31-2023
Join Date: Oct 2007
Posts: 2,520
Thanks: 3,023
Thanked 2,076 Times in 1,156 Posts
Groans: 7
Groaned at 34 Times in 27 Posts
|
thanks, I actually was eventually able to do my code without the need to change the math random thingy, I'll keep your post in mind for future reference though
__________________
"Loyalty to the country always. Loyalty to the government when it deserves it. " -Mark Twain |
|
|
|
![]() |
|
| Tags |
| java, numbers, random |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|