Shuffling arrays question

02282015, 10:42 PM
Post: #1




Shuffling arrays question
Does anyone know of an algorithm to shuffle an array of integers WITHOUT USING RANDOM NUMBER FUNCTIONS? I discovered a good (not the best) method for generating random numbers is that you start with an array of n elements (with values from 1 to n), shuffle the elements of that array and then divide each array element by n+1. You get a good set of random numbers. I can do the shuffling using random number functions, like randperm in Matlab. I am looking for a way to shuffle the array (initially in ascending or descending order) using clever swaps of elements. I am basically looking to transform perfect order into as perfect chaos as possible!
Namir 

02282015, 11:55 PM
(This post was last modified: 03012015 03:33 AM by Mark Hardman.)
Post: #2




RE: Shuffling arrays question
(02282015 10:42 PM)Namir Wrote: Does anyone know of an algorithm to shuffle an array of integers WITHOUT USING RANDOM NUMBER FUNCTIONS? I discovered a good (not the best) method for generating random numbers is that you start with an array of n elements (with values from 1 to n), shuffle the elements of that array and then divide each array element by n+1. You get a good set of random numbers. I can do the shuffling using random number functions, like randperm in Matlab. I am looking for a way to shuffle the array (initially in ascending or descending order) using clever swaps of elements. I am basically looking to transform perfect order into as perfect chaos as possible! You might be able to get a random order using a perfect shuffle: The Mathematics of Perfect Shuffles Thank you for your continued efforts in pushing the limits of randomization. Fascinating stuff. Ceci n'est pas une signature. 

03012015, 12:42 AM
Post: #3




RE: Shuffling arrays question
You are looking for a permutation that appears "random". I'd try looking at permutation ciphers first.
There are methods to generate all permutations of a set, you might be able to pick one of these based on n e.g. let p = floor(n/3) and run the algorithm p times from the initial state. Check out algorithm L.  Pauli 

03012015, 01:10 PM
(This post was last modified: 03012015 01:13 PM by Namir.)
Post: #4




RE: Shuffling arrays question
I was able to write the following unsort function in Matlab. It does well in scrambling an ordered array. The function primes(m) returns an array of primes from 2 to m (or under it):
Code: function x=unsort(x) The number 195 is optimum for sorting an array of 100000 integers in Matlab. While the above code is free of using random number generating functions or code, I feel that the effort needed to scramble an array is not minimal. Namir 

03012015, 06:48 PM
(This post was last modified: 03012015 10:17 PM by Namir.)
Post: #5




RE: Shuffling arrays question
I am working on an arrayshuffling algorithm that divides the array into ten "buckets". The method then merges two neighboring or distant buckets, shuffles them, and then copy the shuffled elements back to their original buckets. So far, I am able to get more randomness than the algorithm I posted earlier.
Here is the Matlab code. You can find this code integrated with a more comprehensive Matlab function in the part 3 article in my web site. Code: function x=unsort(x) 

03072015, 05:56 AM
Post: #6




RE: Shuffling arrays question
http://en.wikipedia.org/wiki/Linear_feed...t_register
Is this what you are looking for? (Statistically random sequence, but the same sequence every time.) 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)