This will create you a random double.
//Creates random double.
double random = Math.random();
//Turns double into a number >=1
double Random = random * 10;
//Cast the double as an int (removes decimals)
int xOry = (int)Random;
> This will create you a random double.
>
> //Creates random double.
> double random = Math.random();
>
> //Turns double into a number >=1
No, because random may be a number less than 0.1
For example, 0.04382 * 10 becomes 0.4382
Perhaps you meant that this expands the range of the random number?
> double Random = random * 10;
>
> //Cast the double as an int (removes decimals)
...by truncation, may not be what you want. Consider Math.round().
> int xOry = (int)Random;
There is some good information on generation of pseudorandom numbers in Java
at
http://mindprod.com/jgloss/pseudorandom.html

Signature
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
j1mb0jay - 08 Feb 2007 23:46 GMT
Sorry have only started messing with java when I started this course at
university, otherwise use to C#, was just trying to help, but if didn't know
it could return 0.0xxx I must edit code to allow for this mistake. Thanks
for the comment.

Signature
Regards JJ (UWA)
>> This will create you a random double.
>>
[quoted text clipped - 20 lines]
> at
> http://mindprod.com/jgloss/pseudorandom.html
Rune Zedeler - 09 Feb 2007 23:58 GMT
> ...by truncation, may not be what you want.
Usually truncation is what you want. Round is normally never what you want.
For instance to throw a dice, use 1+(int)(Math.random()*6).
Math.round(Math.random()*10) gives 0 with 5% probability, 10 with 5%
probability and 1-9 with 10% probability each.
-Rune