Re: An Applied Algorithmic Activity:

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi Patrick,

Patrick Barnes wrote:
> 
> Lets say we want to step through the numbers 1 to N, in a particular
> order. The order of the numbers can be arbitrary, but each number can
> only be visited once, and the order of the visits should be seeded by
> a number passed to it.
> 
> For example:
> 1923840657
> 0123456798
> 7648235910
> 
> It seems like it needs some sort of hash value, but I couldn't for the
> life of me figure out how.
> How would you suggest I do this? Each seed doesn't have to generate a
> unique result, but it would be nice. smile
> -- 

is this a function - which is from Jiri Babor - which might be helpful
for you?:

function shuffle(sequence s)
    object temp
    integer j

    for i = length(s) to 2 by -1 do
        j = rand(i)
        temp = s[j]
        s[j] = s[i]
        s[i] = temp
    end for
    return s
end function


Have a nice day, Rolf

-----------------------------------------------------
| Dr.Rolf Schröder |    E                     B     |
| DESY MST-1       |                C               |
| Notkestraße 85   |          D                     |
| D-22603 Hamburg  |                      A         |
| Earth            |--------------------------------|
| Solar System     | Phone : +49-40-8998-2628       |
| Milky Way        | Fax   : +49-40-8994-2628       |
| Local Group      | mailto:Rolf.Schroeder at DESY.de  |
| Known Universe   | http://desyntwww.desy.de/~rolf |
-----------------------------------------------------

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu