range - Java Not greater than certain value -
range - Java Not greater than certain value -
i have simple question. in java, know remainder of (y%x) can't greater x itself. thus, hypothetically set numbers less value of x, 100. yet opposite of this? if wanted set numbers above value, 20, have range [20,100]?
i thinking subtract 20 both sides have range [0,80], , take modulus of 80, , add together 20 it.
am right in believing this?
thanks.
the random class includes nextint(int) (per javadoc) returns pseudorandom, uniformly distributed int value between 0 (inclusive) , specified value (exclusive), drawn random number generator's sequence. so, 0-80 is
random rand = new random(); int v = rand.nextint(81); if want in ragne 20-100 be
int v = rand.nextint(81) + 20; java range modulus
Comments
Post a Comment