Try to search your question here, if you can't find : Ask Any Question Now ?

Is there a better method for randomizing functions besides Random?

HomeCategory: stackoverflowIs there a better method for randomizing functions besides Random?
Avatarbhawya asked 5 months ago

I have 2 strings in an array. I want there to be a 10% chance of one and 90% chance to select the other. Right now I am using:

Random random = new Random();
int x = random.nextInt(100 - 1) + 1;
if (x < 10) {
    string = stringArray(0);
} else {
    string = stringArray(1);
}

Is this the best way of accomplishing this or is there a better method?

1 Answers
Best Answer
AvatarAmit answered 5 months ago
Your Answer

8 + 0 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com