The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » sci.math.* » sci.math

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Pseudorandom Permutation Algorithm for Arbitrary Size?
Replies: 5   Last Post: Feb 16, 2012 11:39 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 57
Registered: 8/26/09
Re: Pseudorandom Permutation Algorithm for Arbitrary Size?
Posted: Feb 16, 2012 10:10 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Andrew Tomazos <> wrote:
> Given a positive integer N, I would like a function f(N,i) where i is
> in [0,N) such that:
> f(N,0) = x0
> f(N,1) = x1
> f(N,2) = x2
> .
> .
> f(N,N-1) = x[N-1]
> where (x0, x1, x2, ..., x[N-1]) is a pseudo-random permutation of (0, 1,
> 2, .., N-1).
> For example the output for N = 5 may be:
> f(5,0) = 3
> f(5,1) = 0
> f(5,2) = 2
> f(5,3) = 4
> f(5,4) = 1
> Here (3,0,2,4,1) is a "pseudo-random" shuffle of (0,1,2,3,4)
> What is a closed form or algorithm for f?
> - N may be very large, so allocating an identity permutation array and
> randomly shuffling it is out. Ideally calculating f(N,i) for some N
> and i should take constant size and space.
> - If this is not possible than perhaps an easing constraint can be
> added that a stateful solution that guarantees f(N,i) will be called
> in ascending order of i values (ie f(N,0), f(N,1), f(N,2) and so on)
> would be useful to.
> - f doesn't need to be "cryptographic strength", just sufficiently
> random for statistical purposes.)
> - I note that maybe mutliplying by and moding by prime numbers (or
> pure powers of primes) is somehow a useful tool as P^n where P is
> prime forms a valid finite field. ?
> Thanks,
> Andrew.

Generate an array of N random numbers. Generate a second array
of numbers from 0 to N-1, in order. Sort the first array
in ascending order while simultaneously re-arranging the
second array to maintain its relation to the first array.
Use the resulting second array to index your data.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.