Equivalent for arc4random() in Android

1.7k Views Asked by At

I have arc4random() for random in my IOS Project to calculate the random number between 2 to (2^32)-1 it returns (uint32_t values). I want convert the same project to Android I don't know what is the Equivalent function for arc4random() in android to calculate the random number I have also added some of my random numbers in ios below please look on it give me some suggestion to calculate the random number in Android.

Example Random numbers: 1902136219, 575648775, 2003297918, 166044218, 1320498814.

2

There are 2 best solutions below

0
On

You can use Java's Random class, as in:

Random rand = new Random();
int r = rand.nextInt();
0
On

use Math.random(). You can set a range. For example to get a random number between 1 and 10 you would do:

int range =  (maxValue - minValue) + 1;
int randomValue = (Int)(Math.random() * range) + min;