Re: Binary Shuffling
- From: Douglas Eagleson <eaglesondouglas@xxxxxxxxx>
- Date: Mon, 26 Nov 2007 15:10:26 -0800 (PST)
On Nov 25, 7:15 pm, The Ghost In The Machine
<ew...@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
In sci.physics, DouglasEagleson
<eaglesondoug...@xxxxxxxxx>
wrote
on Sun, 25 Nov 2007 12:19:12 -0800 (PST)
<77b78e25-1f77-47e5-987d-2569daf5b...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>:
1 1 1 1 0 0 0 0
A four one word is given. It has also four zero's, making a binary
word. A shuffle will make all the permutations of all the
combinations. This particular combination being four 1's and four 0's.
My question how to shuffle the set?
How is a special shuffle constructed to shuffle all binary's!!!!
A special reference is needed, my thinking I guess. Because each
duplicate 1 or 0 is a combination word, not a permutation word.
ABCDOIUY to replace 11110000 makes a purmutation
One method is to use a pick-and-delete, a destructive
method that picks items and deletes them from the input,
while setting them in the output.
This can be implemented as follows (in C):
char inp[8] = {'1','1','1','1','0','0','0','0'};
int genshuffle( char out[8])
{
for(int i = 8; i > 1; i--)
{
int r = makerand(i);
out[i-1] = inp[r];
for(int j = r+1; j < i; j++)
inp[j-1] = inp[j];
}
out[0] = inp[0];
}
where makerand(n) generates a random integer from 0 to n-1;
the implementation thereof is left to the interested reader.
Various modifications are easily done, among them first
copying the input to the output, then picking the
desired bit in the output and swapping.
If you're more interested in enumerating all possible
shuffles into a list, one can count from 0 to 11110000
and select all numbers containing 4 bits. One easy
way to count the bits is this little hack:
int numbits(int n)
{
int c = 0;
while(n != 0)
{
n &= n-1;
c++;
}
return c;
}
This works because the last 1 bit in n is followed by all 0s,
and is replaced by a 0 bit followed by all 1s in the subtraction.
The AND then eliminates that last 1 bit.
--
#191, ewi...@xxxxxxxxxxxxx
Been there, done that, didn't get the T-shirt.
--
Posted via a free Usenet account fromhttp://www.teranews.com- Hide quoted text -
- Show quoted text -
The shuffle is a random style. It appears correct.
I would feel confident in its use in a deterministic fashion of the
distribution was selectable. As long as each number is hit once in a
shuffle cycle, say.
I will try them out thanks.
Binary shuffling is a hard thing form me to grasp sometimes. I will
also try to make one from a parity generator.
DOug
.
- References:
- Binary Shuffling
- From: Douglas Eagleson
- Re: Binary Shuffling
- From: The Ghost In The Machine
- Binary Shuffling
- Prev by Date: Re: Why Math?
- Next by Date: Re: Energy consumed by a thermometer?
- Previous by thread: Re: Binary Shuffling
- Next by thread: Recent Sam Wormley (?) post on real numbers?
- Index(es):
Relevant Pages
|