Re: Random numbers with no duplicates

From: David White (no_at_email.provided)
Date: 09/26/04


Date: Sun, 26 Sep 2004 19:30:14 +1000


"Francis Glassborow" <francis@robinton.demon.co.uk> wrote in message
news:yPAjdTZ5qfVBFwgP@robinton.demon.co.uk...
> In article <4155f29d@x-privat.org>, Spacen Jasset <a@b.com> writes
> >swap the number at random(1..pick) with the number at the index, pick.
> >decrement the pick index.
> >repeat 10 times.( or until pick = 0, same thing )
>
> To be exact, do it only 9 times, on the tenth time you only have one
> item and it is a bit pointless to randomly select it to swap it with
> itself:-)

I'd say do it 10 times. Why add extra code to select the last value
differently from all the others and add an unnecessary wart onto a very
elegant and fast algorithm? This algorithm, which I've used as a card dealer
since the HP25 calculator, works even if it has to swap the chosen value
with itself, so just let it do that.

DW



Relevant Pages

  • Re: Random numbers with no duplicates
    ... >> To be exact, do it only 9 times, on the tenth time you only have one ... Why add extra code to select the last value ... >elegant and fast algorithm? ... works even if it has to swap the chosen value ...
    (alt.comp.lang.learn.c-cpp)
  • Re: motherboard replaced - but no boot!
    ... the whole point of this mess was to swap the same exact ... mobo and reboot as if nothing had happened. ...
    (microsoft.public.windowsxp.hardware)
  • Re: Parsing challenge to reduce blanks
    ... many ACM regional contests, and ther you have to have the exact answer! ... in this way I think a clear and fast algorithm is what one ...
    (comp.lang.fortran)
  • Re: El Torito Bootable CD boot error - Missing or corrupt ntoskrnl.exe
    ... You may want to guide us through the exact steps you performed. ... > The following error does occur with etprep: Failed to swap El Torito disk ...
    (microsoft.public.windowsxp.embedded)
  • Re: One algorithm problem
    ... If you stay stuck, consider posting the exact ... basic problem or the action of swap. ...
    (comp.programming)