[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: random predicate function
From: |
Tyler Smith |
Subject: |
Re: random predicate function |
Date: |
Mon, 13 Dec 2010 13:17:04 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
"Pascal J. Bourguignon" <pjb@informatimago.com> writes:
>
> You shoud not use sort to randomize, because it's suboptimal
> [ O(n*log(n)) at best instead of O(n) ].
>
> And foremost, you should not use a predicate that is not a total order
> because this usually gives invalid results.
I don't know what a 'total order' means. Is the result of the predicate
invalid or the actual sorting?
>
> Google for: shuffle algorithm.
Thanks. I knew there must be a name for what I was trying to do.
> You could instead put your paragraphs in a vector and use:
>
> (defun shuffle (vector)
> "Re-orders randomly the vector."
> (loop
> for i from (1- (length vector)) downto 1
> do (rotatef (aref vector i) (aref vector (random i)))))
>
> to shuffle them and then re-insert them.
Thanks for this! Very helpful.
Tyler
- Re: random predicate function, Pascal J. Bourguignon, 2010/12/13
- Re: random predicate function,
Tyler Smith <=
- Message not available
- Re: random predicate function, Ted Zlatanov, 2010/12/13
- Re: random predicate function, Pascal J. Bourguignon, 2010/12/13
- Re: random predicate function, Ted Zlatanov, 2010/12/15
- Re: random predicate function, Pascal J. Bourguignon, 2010/12/15
- Re: random predicate function, Ted Zlatanov, 2010/12/15
- Re: random predicate function, Pascal J. Bourguignon, 2010/12/15
- Re: random predicate function, Ted Zlatanov, 2010/12/15
- RE: random predicate function, Drew Adams, 2010/12/15