Sponsored Link •

Legacy Java Answers Forum
February 2002

 Advertisement

 Advertisement This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums. Message: just a suggestion Posted by ping203 on February 22, 2002 at 6:24 PM Hi,I am not too good at Math, but here is my suggestion.Using the way you generate random, 1-10, total 10 possibilities.Let say you want the probablity accurate to 0.01, 0 - 0.11 - 0.22 - 0.213 - 0.094 - 0.15 - 0.16 - 0.27 - 0.068 - 0.019 - 0.0110 - 0.01total - 1.00Then, you create an array, size 100. Then, you put 10 1's, 20 2's, 21 3's, 10 4's,...,1 10 in this array.Then, instead generating 1-10, you generate 0-99(array index). The probability of each random number is the same(assume Java does a good job)Then, use this random number to index the array.The result will be you get 1 in 1 out of 10, 2 in 2 out of 10,..., 10 in 1 out of 100.(the way you store 1-10 in the array does matter, as long as the number of each NUMBER is the same as the probability you want it to be drawn.)hope you can understand me.good luckPing Replies: Thanks Ping!!! Avin Sinanan February 23, 2002 at 11:57 AM (0)

 Sponsored Links

 Web Artima.com
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us