in reply to Re^2: Generating 0 .. N Randomly and Efficiently
in thread Generating 0 .. N Randomly and Efficiently

How does Velaki's solution use more memory (except maybe for (@a), which could be replaced with for ($j=0; $j<@a; $j++))?

Update: Ah yes, you return an interator instead of building an actual list.

Replies are listed 'Best First'.
Re^4: Generating 0 .. N Randomly and Efficiently
by Limbic~Region (Chancellor) on Oct 19, 2004 at 16:37 UTC
    ikegami,
    As you noted, the list is never constructed - there is only an iterator that finds the next randomly chosen number. Additionally, a bitstring is compact. If you wanted to generate 0 .. 80_000_000, it would create a bitstring only about 1 mb in size.

    Cheers - L~R