IOS developers will certainly encounter random numbers. For the moment, there seems to be an arc4random (). So if you want to get a random number from 80 to 100, you can write it as int randomnumber.
=Arc4random ()+ 80
Int Index = Arc4random () % 6 + 1; is the random number from 1 to 6.There are also many other methods to obtain random numbers. On the Forum, users often discuss how to generate random numbers that are not repeated, that is, to generate a Random Seed, such as srand (Time (null ));
Rand ()
% 1000;There is another such function round (random () + 10); the result is 10 ~ The number between 24, but a pseudo-random number.
How to obtain a random number between 0 and 1, excluding 0 and 1. The idea is: Calculate the random number between 1-100 and then/srand (time (0 ));
(Float) (RAND () % 100)/100;
(Float) (1 + arc4random ()/100 conclusion: it is best to use arc4random for random numbers, because Random Seed srandom (Time (null) must be set manually when random () is used )); otherwise, a pseudo-random number is generated. Some netizens have the following idea: Nsarray * temp = [nsarray arraywithobjects: @ "1", @ "2", @ "3", @ "4", @ "5", @ "6 ", nil];
Nsmutablearray * temparray = [[nsmutablearray alloc] initwitharray: temp];
Nsmutablearray * resultarray = [[nsmutablearray alloc] init];
Int I;
Int COUNT = temp. count;
For (I = 0; I <count; I ++ ){
Int Index = arc4random () % (count-
I );
[Resultarray addobject: [temparray objectatindex: Index];
[Temparray removeobjectatindex: Index];
}
[Temparray release];
Nslog (@ "resultarray
Is % @ ", resultarray );
In resultarray, The intvalue of each object is the random number you want.