Re: Random numbers with no duplicates
From: David White (no_at_email.provided)
Date: 09/26/04
- Next message: Francis Glassborow: "Re: Random numbers with no duplicates"
- Previous message: Niklas Borson: "Re: [C++] returing object from functions"
- In reply to: Francis Glassborow: "Re: Random numbers with no duplicates"
- Next in thread: Francis Glassborow: "Re: Random numbers with no duplicates"
- Reply: Francis Glassborow: "Re: Random numbers with no duplicates"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Francis Glassborow: "Re: Random numbers with no duplicates"
- Previous message: Niklas Borson: "Re: [C++] returing object from functions"
- In reply to: Francis Glassborow: "Re: Random numbers with no duplicates"
- Next in thread: Francis Glassborow: "Re: Random numbers with no duplicates"
- Reply: Francis Glassborow: "Re: Random numbers with no duplicates"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|