java - Random Class not working on Android 4.1+ -
this code using generate random set of numbers:
... public boolean placetreasure() { randomgen = new random(); int[] treasureloc = {0, 0}; while (treasureloc[0] < 2 || treasureloc[1] < 2) { treasureloc[0] = randomgen.nextint(rows - 2); treasureloc[1] = randomgen.nextint(columns - 2); system.out.println("" + treasureloc[0] + ", " + treasureloc[1]); } maze[treasureloc[0]][treasureloc[1]] = '*'; homecoming true; } ...
the funny thing works fine on before versions of android. far know, above 4.1 not run properly. gives me pairs of 0, 0
. leads me believe either 4.1+ not back upwards random class, or else weird going on implementation. method works fine on before versions though, i'm not sure what's going on.
if has suggestions on alternate implementations of (i need generate random integers between 2
, rows
or columns
).
if has suggestions on alternate implementations of (i need generate random integers between 2 , rows or columns).
yes, simply:
int randomrow = randomgen.nextint(rows - 2) + 2; int randomcol = randomgen.nextint(columns - 2) + 2;
java android random
No comments:
Post a Comment