Link to home
Start Free TrialLog in
Avatar of rite_eh
rite_eh

asked on

random number generator

Hello,

I need to have a vb function that I can call which will return a 7 digit hash or random and unique number, based on a string it is passed. This number must be unique and could be calculated using the string itself or any other method, such as the date and time for example. If necessary the string can be limited to a fixed number or characters, within reason (perhaps 40 or 50 characters). I have already written a routine which simply returns the current time and first digit of the day (DHHMMSS) however this same number could be assigned to another element in the future. Checking to see if a number is already in use is possible, but I would prefer to avoid it since these numbers are being outputted to a flat file.

Thanks in advance for any suggestions or code.
SOLUTION
Avatar of rettiseert
rettiseert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wraith821
wraith821

if the application needs to be run from more then one machine then you could save the number in a file, or some other common location.
Avatar of rite_eh

ASKER

The problem is that there is still a small a chance a number could be returned more than once. But then again I suppose even a hash of the value could potentially have a collission, although I would expect it is less likely (especially if I disallow adding elements with the same name)
Avatar of rite_eh

ASKER

wraith821, I like the idea of using a different base. Thanks for the link. I'll leave this question open until tomorrow and then divide the points up between all the people offering suggestions and code.

Thanks
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial