how to generate random numbers widout repeating them

  • 12 years ago

    how can i generate random nos. in ... "without repeating them" ... i don't want to use arrays to remember the sequence of nos. generated because it can get too long ... is there any way to do that ??

  • 12 years ago
    I’d be interested to see if anyone has any suggestions.  I’m not convinced that this is possible.

    If you don’t persist the numbers in an array or some other collection, how else do you know that subsequent numbers haven’t already been created before in the past?

  • 12 years ago

    well if i store it in some structure it would b ok for some small structures but as the structures get big in size ... its has to remember gr8 many nos.. so it could take a lot of time to generate one ..   would it not ..

    wud b thankful if u helped 

  • 12 years ago

    First comes question: do you need unique sequences or unique numbers. I will suppose you need unique if you get 15 its last time for this number. No, in material world you must remember if you don't want to repeat. Bt you can still make two things: create fixed size array, and remember only some numbers. You can let only most rated numbers in this "filter memory". But we are talking about random numbers, so you can simply push new numbers to top of this array and remove old from bottom, and you should get same result. Also you can add some math to it. For example if you remembered two values (or more) in one integer (you store them multiplied and then you check if no filter item is dividable by "new random" number. By this compression you could get some more place, but exclude some good results as wrong. But is there some reason to cry for "some random numbers"? Maybe: wrong excluding in combination with multipliing and dividing is much slower. Nice question...anyway.Smiley Face

  • 12 years ago
    That's a very interesting idea with the multiplying and dividing :)

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Walking on water and developing software from a specification are easy if both are frozen.” - Edward V Berard