Jump to content

  • Log In with Google      Sign In   
  • Create Account

[java] random numbers in java...?


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1   Members   

122
Like
Likes
Like

Posted 05 February 2001 - 06:25 AM

I am new to java. What is the java equivolent to rand() in C/C++? Thanks, Briar->LoDeran();

#2   Members   

122
Like
Likes
Like

Posted 05 February 2001 - 07:01 AM

Math.random() returns a double in range 0.0-1.0

#3   Members   

122
Like
Likes
Like

Posted 05 February 2001 - 12:51 PM

actually, i don''t think it reaches 1.0.
for example, if u want a random number between 1 and 5, you would do
Math.random()*5 + 1

min is 0.0*5 + 1 = 1
max is .999*5 + 1 = 5.995


#4   Members   

122
Like
Likes
Like

Posted 06 February 2001 - 02:18 PM

Thanks a lot guys. It was so simply I feel stupid, but often times feeling stupid is part of learning...! ...right?!?

Briar->LoDeran();




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.