Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
random choice with prob in java
Name: karim Date: May 7, 2005 at 12:41:51 Pacific OS: xp CPU/Ram: 1.8
Comment:
Hi guys, Anybody knows how to randomly choose one of two numbers but with specifying a probability. For exemple, each time randomly choose one of two colored balls, knowing that you have a 75% probality to choose the red ball. something lke that...any ideas? I would really apreciate the help thank you in advance
Thank you guys a bunch. I couldnt figure it out even if its too simple. No need then to have a special function to do that for you in Java. something like this I guess should work:
Random rand = new Random(); int choice = (rand.nextInt(100)<75) ? 1 : 0;
it should pick the number 1 with a probability of 75% :-) Gotta get back to my code now! Thanks for the tip guys Sane
Summary: Hey guys, would any of you know how I would go about generating a random normally distributed vector in java? Or where I could get the code for the matlab randn function? Thanks. ...
Summary: Hello, I'm trying to write a program in JAVA, to calculate the number of integer values entered as a string by the user and work out the average of numbers. The final output should display the numbers...