How to generate 40-bit unique values randomly?
I'd like to generate 40-bit values, which are unique and non [so easily] guessable.
How can I do it? Any suggestions?
-edit-
I'm interested in an algorith开发者_StackOverflowm, C# or Java would be the cherry in the top of the cake!-edit2-
I'm able to store previous values but I wouldn't like to have to check the whole list everytime I generate a new numberWhat platform are you on? On unix-ish systems, just read 40bits from /dev/random (blocks if insufficient entropy is available) or /dev/urandom (doesn't block, but also produces lower-quality random numbers if entropy is limited).
get first 12 bit(upto max 4095) as day from first release of ur program(will be unique part), other 38 bit use from random system call/function. so u have recheck last day only values for unique. sorry, no way GRANT unique from non-predictable(random) value.
u can use more part from date, upto seconds for example. u can shafle predictable(date) bits, but it will nto add security.
anyway u have to balance between unique check time/random quality. to increase speed of check, can use binary tree or other technics.
also u can use timer value upto miliseconds.. for busy system it will be unique(if do thread lock+ 50ms sleep) and not so predictable in multithreaded environment.
usign what? in general random =unqiue,so use random. or
date|md5sum|cut -b 4-9
something like that
精彩评论