generate random number [modified]
-
Hi all, In Vb2005, I need to develop a program that sends alphanumeric sequences to a device. These sequences have to be random and must not repeat any previous one done during the same day. I cannot store the used sequences, neither in disk nor in memory. Any idea on how to do that? thanks in advance, Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits
-
Hi all, In Vb2005, I need to develop a program that sends alphanumeric sequences to a device. These sequences have to be random and must not repeat any previous one done during the same day. I cannot store the used sequences, neither in disk nor in memory. Any idea on how to do that? thanks in advance, Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits
You haven't said anything describing these "random sequences". How long are they? Variable length? What are the legal characters? Any illegal characters? Does if have to be in a certain format? Can the sequences be patially similar to previous ones in the same day? (Like "these" and "this") You're going to have to "remember" the sequences somewhere to make sure that you don't use the same one twice. "Random" doesn't mean "unique" acrossed the set of available numbers.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
You haven't said anything describing these "random sequences". How long are they? Variable length? What are the legal characters? Any illegal characters? Does if have to be in a certain format? Can the sequences be patially similar to previous ones in the same day? (Like "these" and "this") You're going to have to "remember" the sequences somewhere to make sure that you don't use the same one twice. "Random" doesn't mean "unique" acrossed the set of available numbers.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Hi Dave, these random sequences have to be 6 digits long and composed using 0 to 9 and A to Z characters. The intention was to make an alphanumerical counter but we want something more elaborated that seems a random number. I was thinking to use an encrption algorithm where the string to encrypt shoud be the counter. By this way I shouldn't have to store the strings already done and I just have to store the actual counter value. Thanks, Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits
-
Hi Dave, these random sequences have to be 6 digits long and composed using 0 to 9 and A to Z characters. The intention was to make an alphanumerical counter but we want something more elaborated that seems a random number. I was thinking to use an encrption algorithm where the string to encrypt shoud be the counter. By this way I shouldn't have to store the strings already done and I just have to store the actual counter value. Thanks, Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits
You could do this, but ANY RNG can generate the same sequence of characters somewhere down the line, however unlikely it may seem. RNGCryptoServiceProvider Class[^].
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Hi all, In Vb2005, I need to develop a program that sends alphanumeric sequences to a device. These sequences have to be random and must not repeat any previous one done during the same day. I cannot store the used sequences, neither in disk nor in memory. Any idea on how to do that? thanks in advance, Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits
Hi Marc, The first thing that comes to mind is to make use of
Now()
. Whenever you call it, it will give you a different value, and it will never ever repeat. You could for example use its.Hour
,.Minute
and.Second
parts, and replace leading zeros with a random letter from A to Z. Alternatively each datetime is a number as far as the computer is concerned, and will also nerver ever repeat, so you could use that in some sort of algorithm or formula. JohanMy advice is free, and you may get what you paid for.
-
You could do this, but ANY RNG can generate the same sequence of characters somewhere down the line, however unlikely it may seem. RNGCryptoServiceProvider Class[^].
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Hi again, as I said I don't really need a random number, I just need a unique 6 digit number that it seems random, so, do you a encryption wrapper class that takes a 6 digit counter and encrypts it to a 6 digit alphanumeric string. That would do the job, but I don't know which one does it!! Thanks in advance, Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits