[OT] shuffling lines in a stream
Sergey Gromov
snake.scaly at gmail.com
Fri Oct 10 14:58:34 PDT 2008
Fri, 10 Oct 2008 16:27:03 -0500,
Andrei Alexandrescu wrote:
> > while (a.length || b.length)
> > {
> > if (uniform(gen, 0, a.length + b.length) < a.length)
> > {
> > ab.put(a.head);
> > a.next();
> > }
> > else
> > {
> > ab.put(b.head);
> > b.next();
> > }
> > }
>
> This should work. Use of ranges noted :o).
Actually I felt an urge to write:
if (uniform(gen, 0, a.length + b.length) < a.length)
ab.put(a.next);
else
ab.put(b.next);
I had to really get hold of myself. ;)
More information about the Digitalmars-d
mailing list