Generate Full Random Number with Percentage Android -
i trying generate random number percentage, this:
60% chance generate number 70 100,
20% chance generate number 50 70
and on , set in textview. reason, getting weird long decimal numbers 0.44859123121 etc etc, how can generate total numbers? 99,80,70 etc etc. code:
random rng = new random(); double doubl = math.random(); if (doubl < 0.6) { int r1 = rng.nextint(100 - 70) + 70; // 60% chance } else if (doubl < 0.65) { int r1 = rng.nextint(0 - 30) + 0; // 5% } else if (doubl < 0.80) { // 15% chance int r1 = rng.nextint(30 - 50) + 30; } else { // 20% chance int r1 = rng.nextint(50 - 70) + 50; } result.settext(doubl+"%");
put generated random integer r1
in result, not doubl
random number between 0 , 1.
also prepare calls nextint()
you're not calling negative value. illustration 70 - 50
instead of 50 - 70
.
android random integer
No comments:
Post a Comment