• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to generate a random value?  RSS feed

 
Avin Sinanan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I was wondering if anyone knows how to gerenerate a raddom variable about a certain number.
For example if I wanted to generate a random number about 10 then the numbers 8, 9, and 11 and 12 would be very very common..well much more common that 1 and 2 and 3 and 20 and so on.
Any ideas or code?
yours Respectfully Avin Sinanan
 
Tris Rabar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Avin,
I know you can use the method Math.random() to generate random numbers, whose values can be given a limit, for example:

I believe would generate random numbers from 0 to 9.
Maybe you can investigate this further to see if there's a workaround to suit your particular need.
 
Avin Sinanan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Tricia thanks..
I was trying to use that same line of cide u gave me to do it. But I wasn't making any progress.
If u come up with anything please let me know.
Thanks by the way
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avin,
You asked this same question about a month ago, and forgive my being conceited, you got a pretty darn good answer. Here's the link:
Implementing probability in Java
Good Luck.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!