开发者

same random number should not generate again and again? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicates:

C++ random number generator without repeating numbers

Unique random numbers in O(1)?

I am doi开发者_运维百科ng as following

int y = arc4random() % 50;

I am using objective-c Now as I don't want same number again and again, like if 6 is once I get, then I don't need 6 again, because I am calling this line again and again and taking random numbers.


How about you generate an array (1,2,3,4,5,6,...) and sort it randomly, then read the array elements one at a time.

Otherwise, if you use a random number generator and make sure it only gives you numbers you haven't seen before, you can only call it a limited number of times.

sorting randomly will depend on what language you're using.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜