Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to java , need help with random generation of a number

Status
Not open for further replies.

goaganesha

Programmer
Dec 4, 2001
178
BE
Hello,

I'm trying to generate a random int between 1 and 39.

If I use:
int count = Math.round(Math.ceil(Math.random()*39));

I keep getting following compiler error:
possible loss of precision:long,required: int

If I use:

long count = Math.round(Math.ceil(Math.random()*39));


it works fine but it seems impossible to cast count back to an int.

Any suggestions?

thanks in advance, goaganesha
 
Problem solved. It was easier than i thought
int count=(int)(Math.random()*39);

regards, goaganesha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top