lundi 16 février 2015

Java Random - how to keep the value?

Completely stuck with Java Random. Digging whole bunch of info but can not solve this. I need to generate new random values of randomWidth and randomHeight only at the beginning and after drawBitmap becomes false again. But as you can see here I generate new random values each time I am loopping. How to keep once generated randomWidth and randomHeight until: drawBitmap = false; startTime = System.currentTimeMillis(); ??



long startTime;
boolean drawBitmap;
//
Random rnd = new Random();

randomWidth = rnd.nextInt((100 - 10) + 100);
randomHeight = rnd.nextInt((200 - 10) + 200);
//


while (true) {

if (System.currentTimeMillis() - startTime >=5000) {
drawBitmap = true;

}

if (System.currentTimeMillis() - startTime >= 10000) {
drawBitmap = false;
startTime = System.currentTimeMillis();
}

if (drawBitmap) {
canvas.drawBitmap(chooseRandomBitmap(map), randomWidth, randomHeight, p);
}
}




Aucun commentaire:

Enregistrer un commentaire