Since you already have database, create a source table with full range, and then pick any from that table, with marking/deleting that number from source table. This is quickest solution for large number of data.
On Mon, Sep 27, 2010 at 1:29 AM, Kristofer Karlsson < [email protected]> wrote: > I wrote a blog article about this very topic. > > Basically I have an algorithm that in constant time amortized (assuming > hash lookups can be done in constant time) can provide a new distinct random > integer. > > Memory usage is O(K) for retrieving K distinct integers. > > http://krkadev.blogspot.com/2010/08/random-numbers-without-repetition.html > > > > On Sat, Sep 25, 2010 at 8:56 PM, peeyush Agrawal < > [email protected]> wrote: > >> or use the way you know, generate number, evaluate hash value check if it >> already exists, otherwise insert in hash for further usage.... >> >> >> On Sun, Sep 26, 2010 at 12:22 AM, Lev Neiman <[email protected]>wrote: >> >>> Use a Knuth shuffle or something. That is generate an array which >>> contains values in a certain range of numbers, then shuffle them, then just >>> iterate through array to get your unique random numbers. >>> - Lev Neiman >>> >>> >>> >>> On Sat, Sep 25, 2010 at 2:47 PM, Erick Njenga <[email protected]>wrote: >>> >>>> That would mean that I have to check for duplicates in the database each >>>> time a new number is generated. or do you have pointers to random number >>>> generators which guarantee uniqueness? >>>> >>>> >>>> On Sat, Sep 25, 2010 at 8:52 PM, Lev Neiman <[email protected]>wrote: >>>> >>>>> Your problem is that you need to create random values to put on each >>>>> scratch card? Why not just use rand() or some more advanced random number >>>>> generator? >>>>> - Lev Neiman >>>>> >>>>> >>>>> On Sat, Sep 25, 2010 at 8:37 AM, Erick Njenga <[email protected]>wrote: >>>>> >>>>>> I'm creating an application that involves scratch-cards and would like >>>>>> to know what solutions are available for generating the numbers. Any hash >>>>>> function suggestions? >>>>>> >>>>>> -- >>>>>> >>>>>> Thanks and Regards, >>>>>> Erick Njenga Nyachwaya, >>>>>> M: +254-725-008-790 >>>>>> >>>>>> >>>>>> <http://www.facebook.com/ErickNjenga><http://www.twitter.com/ErickNjenga> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "google-codejam" group. >>>>>> To post to this group, send email to [email protected]. >>>>>> To unsubscribe from this group, send email to >>>>>> [email protected]<google-code%[email protected]> >>>>>> . >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/google-code?hl=en. >>>>>> >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "google-codejam" group. >>>>> To post to this group, send email to [email protected]. >>>>> To unsubscribe from this group, send email to >>>>> [email protected]<google-code%[email protected]> >>>>> . >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/google-code?hl=en. >>>>> >>>> >>>> >>>> >>>> -- >>>> >>>> Thanks and Regards, >>>> Erick Njenga Nyachwaya, >>>> M: +254-725-008-790 >>>> >>>> <http://www.facebook.com/ErickNjenga><http://www.twitter.com/ErickNjenga> >>>> >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "google-codejam" group. >>>> To post to this group, send email to [email protected]. >>>> To unsubscribe from this group, send email to >>>> [email protected]<google-code%[email protected]> >>>> . >>>> For more options, visit this group at >>>> http://groups.google.com/group/google-code?hl=en. >>>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "google-codejam" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]<google-code%[email protected]> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/google-code?hl=en. >>> >> >> >> >> -- >> This may harm your computer, sender not responsible..... >> >> Regards >> Peeyush Agrawal >> M.Tech. >> Indian Institute of Technology >> New Delhi >> >> +917827857543. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "google-codejam" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<google-code%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/google-code?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "google-codejam" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-code%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-code?hl=en. > -- You received this message because you are subscribed to the Google Groups "google-codejam" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-code?hl=en.
