Jalpesh

Hi,

I would like to make an application that generates unique numbers (numerics only) in sequential order (better if this way but not compulsory).

It should be able to recover in case of a crash. i.e. if the generation crashes or system crashes, then the next time its up, it should give unique numbers only, and not repeat any number previously given. This is of utmost importance.

And if crash recovery feature doesn't involve I/O, it would be better. (e.g saving numbers to disk and stuff).

Note: Random is not mandatory, unique is.

If you have a solution to this, please help.

Thank you.


Re: Visual C# Express Edition Generating Unique Numbers

JohnWein

Store the last number in the Registry.



Re: Visual C# Express Edition Generating Unique Numbers

Jalpesh

The time involved in writing a number to registry is too much. And as far as possible I want something like a guid only numeric and unique. So that I don't have to bother about storing it.

And if while storing to the registry, the app or system crashes, what to do then. I want a reassurance that in case of a crash, I can resume generating unique numbers.

The ticks is one way, but if someone resets the system clock, I will get numbers already generated.




Re: Visual C# Express Edition Generating Unique Numbers

jrboddie

I'll go out on a limb and state that without storage (or I/O to something with memory) this is impossible.





Re: Visual C# Express Edition Generating Unique Numbers

jo0ls

I'll join you on that limb and jump up and down.

(you could use a web service, I suppose, but that's getting silly.)





Re: Visual C# Express Edition Generating Unique Numbers

Jalpesh

Would you kindly tell me an approach to the way you are thinking.




Re: Visual C# Express Edition Generating Unique Numbers

jimmygyuma

Don Lancaster in his book CMOS Cookbook described a circuit which used shifts and exor of particular bits to generate non-repeatable random numbers. There was a different circuit for each range, i.e., 16-bit, 32-bit, etc. As I remember, it was guaranteed to generate all possible numbers without repeating. The circuits were easily translated to code.

The simplest solution is to simply count, wherever you start, just add 1 to the last number.

However you do it, you're going to have to remember at least the last number. Save it when you generate it.

As for crashes, if it crashes while generating you haven't generated that number and on recovery the number it would have generated will be your first. If it crashes any other time, you've saved your last generated number, so no problem.

You're going to have to save something, somewhere. Not even you could generate unique numbers if your memory were wiped clean after each one!





Re: Visual C# Express Edition Generating Unique Numbers

nobugz

Just use System.Guid.