is there a way to use Math.random and only request odd integers??? this is the code i use for n as any random number...
Code:n = (int)Math.floor(Math.random()*50+1);
but i want n to be odd each time...
any suggestions
thanks in advance annie :)
Printable View
is there a way to use Math.random and only request odd integers??? this is the code i use for n as any random number...
Code:n = (int)Math.floor(Math.random()*50+1);
but i want n to be odd each time...
any suggestions
thanks in advance annie :)
i think i did it
after suffering by putting this as a while loop
and
while (n !=0)
if(n % 2 == 0 ) //if even choose another num
else //odd was produces; contine with code
i just did this
Code:n = (int)Math.floor(Math.random()*50+1);
Random r = new Random();
n = ( 2 * r.nextInt(25) ) +1;