Question: Came across this question previously on an interview. The requirements are to write a function that

1. Generates a number between 0..1
2. Never returns the same number
3. Can scale (called every few milliseconds and continuously for years)
4. Can use only 1mb of heap memory
5. Does not need to return as a decimal, can render directly to stdout

My idea was hacky at best which involved manipulating a string of the "0.1" then "0.11" then "0.12" etc. Since the requirements did not mention it had to be uniformly distributed, it does not need to be random. Another idea is generate a timestamp of the form yyyyMMddhhmmssSSS (where SSS is msec) then convert that to a string and prefix it with "0." . This way the values will always be unique.

It's a pretty open ended question and I'm curious how other people would tackle it.

Answer: 
Pseudo code that can do what you except *guarantee* no repeats.

1. Take your 1 MB allocation.
2. Randomly set every byte.
3. Echo to stdout as "`0.<bytes as integer string>`" (will be very long)
4. Go to #2

Your "Never returns the same number" is not guaranteed but it is extremely unlikely (1 in 2^8192) assuming a good implementation of Random.
Yes, because there is no random requirement, you have a lot of flexibility.

The idea here I think is *very close* to that of enumerating all strings over the regular expression `[0-9]*` with a couple modifications: 

* the real string starts with the sequence `0.`
* you cannot *end* with a 0

So how would you enumerate? One idea is

```
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.11 0.12 0.13 0.14 0.15 ... 0.19 0.21 0.22 ... 0.29 0.31 ... 0.99 0.101 0.102 ...

```

The only state you need here is an integer I think. Just be clever in skipping those zeros at the end (not difficult really). 1 MB of memory should be fine. It stores a massive massive integer, so I think you would be good here.

(It is different from yours because I generate all one character strings, then all two character strings, then all three character strings, ... so I believe there is no need for state other than the last number generated.)

Then again I may be wrong; I haven't tried this.

**ADDENDUM**

Okay I will try it. Here is the generator in Ruby

```
i = 0
while true
  puts "0.#{i}" if i % 10 != 0
  i += 1
end

```

Looks okay to me....