0

Possible Duplicates:
C++ random number generator without repeating numbers
Unique random numbers in O(1)?

I am doing 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.

Community
  • 1
  • 1
Chatar Veer Suthar
  • 15,541
  • 26
  • 90
  • 154
  • 1
    What language are you using? Please tag your question with it. – alexn Jun 10 '11 at 06:15
  • 2
    http://stackoverflow.com/questions/4299401/which-of-these-algorithm-is-better-in-performance-and-order-for-generating-n-uniq/4299411#4299411 http://stackoverflow.com/questions/1858610/different-numbers-from-1-to-10/1858800#1858800 http://stackoverflow.com/questions/4111214/c-random-number-generator-without-repeating-numbers/4111248#4111248 and so on. – paxdiablo Jun 10 '11 at 06:21

1 Answers1

0

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.

pavium
  • 14,808
  • 4
  • 33
  • 50