###Random distribution is off###
Random distribution is off
When you say "random binary vector" I think each digit has a 50% chance of being 0 or 1. What you have actually generated are binary vectors where each digit has a far greater chance of being a 0 than a 1.
Your current algorithm has two steps:
- Generate a random number of bits
t
from 0 to 8. - For each of
t
bits, randomly place a 1-bit in the output vector, even if it overlaps with a previously placed 1-bit.
Just from step #1, you can see that the random distribution will be off, because 1/9 of the time, you will get all zeroes in the output vector. Also, you will never get an output vector with all ones.
And because in step #2 you allow bits to overlap, you often won't even get as many 1-bits as the t
picked in step #1.
###Generating t
bits correctly###
Generating t
bits correctly
From your comment, it seems like you intended to generate t
1-bits, where t
could chosen to be in the range 0..p
. The way to do that properly would be:
- Generate
t
1-bits and the rest 0-bits. - Shuffle the vector (for example using a Fisher-Yates shuffle).
###Returning the array###
Returning the array
I would modify your program to actually return the array instead of calling a function called returnarray()
. You could then print the array from main
.
###Random distribution is off###
When you say "random binary vector" I think each digit has a 50% chance of being 0 or 1. What you have actually generated are binary vectors where each digit has a far greater chance of being a 0 than a 1.
Your current algorithm has two steps:
- Generate a random number of bits
t
from 0 to 8. - For each of
t
bits, randomly place a 1-bit in the output vector, even if it overlaps with a previously placed 1-bit.
Just from step #1, you can see that the random distribution will be off, because 1/9 of the time, you will get all zeroes in the output vector. Also, you will never get an output vector with all ones.
And because in step #2 you allow bits to overlap, you often won't even get as many 1-bits as the t
picked in step #1.
###Generating t
bits correctly###
From your comment, it seems like you intended to generate t
1-bits, where t
could chosen to be in the range 0..p
. The way to do that properly would be:
- Generate
t
1-bits and the rest 0-bits. - Shuffle the vector (for example using a Fisher-Yates shuffle).
###Returning the array###
I would modify your program to actually return the array instead of calling a function called returnarray()
. You could then print the array from main
.
Random distribution is off
When you say "random binary vector" I think each digit has a 50% chance of being 0 or 1. What you have actually generated are binary vectors where each digit has a far greater chance of being a 0 than a 1.
Your current algorithm has two steps:
- Generate a random number of bits
t
from 0 to 8. - For each of
t
bits, randomly place a 1-bit in the output vector, even if it overlaps with a previously placed 1-bit.
Just from step #1, you can see that the random distribution will be off, because 1/9 of the time, you will get all zeroes in the output vector. Also, you will never get an output vector with all ones.
And because in step #2 you allow bits to overlap, you often won't even get as many 1-bits as the t
picked in step #1.
Generating t
bits correctly
From your comment, it seems like you intended to generate t
1-bits, where t
could chosen to be in the range 0..p
. The way to do that properly would be:
- Generate
t
1-bits and the rest 0-bits. - Shuffle the vector (for example using a Fisher-Yates shuffle).
Returning the array
I would modify your program to actually return the array instead of calling a function called returnarray()
. You could then print the array from main
.
###Random distribution is off###
When you say "random binary vector" I think each digit has a 50% chance of being 0 or 1. What you have actually generated are binary vectors where each digit has a far greater chance of being a 0 than a 1.
Your current algorithm has two steps:
- Generate a random number of bits
t
from 0 to 8. - For each of
t
bits, randomly place a 1-bit in the output vector, even if it overlaps with a previously placed 1-bit.
Just from step #1, you can see that the random distribution will be off, because 1/9 of the time, you will get all zeroes in the output vector. Also, you will never get an output vector with all ones.
And because in step #2 you allow bits to overlap, you often won't even get as many 1-bits as the t
picked in step #1.
###Generating t
bits correctly###
From your comment, it seems like you intended to generate t
1-bits, where t
could laterchosen to be configurablein the range 0..p
. The way to do that properly would be:
- Generate
t
1-bits and the rest 0-bits. - Shuffle the vector (for example using a Fisher-Yates shuffle).
###Returning the array###
I would modify your program to actually return the array instead of calling a function called returnarray()
. You could then print the array from main
.
###Random distribution is off###
When you say "random binary vector" I think each digit has a 50% chance of being 0 or 1. What you have actually generated are binary vectors where each digit has a far greater chance of being a 0 than a 1.
Your current algorithm has two steps:
- Generate a random number of bits
t
from 0 to 8. - For each of
t
bits, randomly place a 1-bit in the output vector, even if it overlaps with a previously placed 1-bit.
Just from step #1, you can see that the random distribution will be off, because 1/9 of the time, you will get all zeroes in the output vector. Also, you will never get an output vector with all ones.
And because in step #2 you allow bits to overlap, you often won't even get as many 1-bits as the t
picked in step #1.
###Generating t
bits correctly###
From your comment, it seems like you intended to generate t
1-bits, where t
could later be configurable. The way to do that properly would be:
- Generate
t
1-bits and the rest 0-bits. - Shuffle the vector (for example using a Fisher-Yates shuffle).
###Random distribution is off###
When you say "random binary vector" I think each digit has a 50% chance of being 0 or 1. What you have actually generated are binary vectors where each digit has a far greater chance of being a 0 than a 1.
Your current algorithm has two steps:
- Generate a random number of bits
t
from 0 to 8. - For each of
t
bits, randomly place a 1-bit in the output vector, even if it overlaps with a previously placed 1-bit.
Just from step #1, you can see that the random distribution will be off, because 1/9 of the time, you will get all zeroes in the output vector. Also, you will never get an output vector with all ones.
And because in step #2 you allow bits to overlap, you often won't even get as many 1-bits as the t
picked in step #1.
###Generating t
bits correctly###
From your comment, it seems like you intended to generate t
1-bits, where t
could chosen to be in the range 0..p
. The way to do that properly would be:
- Generate
t
1-bits and the rest 0-bits. - Shuffle the vector (for example using a Fisher-Yates shuffle).
###Returning the array###
I would modify your program to actually return the array instead of calling a function called returnarray()
. You could then print the array from main
.
###Random distribution is off###
When you say "random binary vector" I think each digit has a 50% chance of being 0 or 1. What you have actually generated are binary vectors where each digit has a far greater chance of being a 0 than a 1.
Your current algorithm has two steps:
- Generate a random number of bits
t
from 0 to 8. - For each of
t
bits, randomly place a 1-bit in the output vector, even if it overlaps with a previously placed 1-bit.
Just from step #1, you can see that the random distribution will be off, because 1/9 of the time, you will get all zeroes in the output vector. Also, you will never get an output vector with all ones.
And because in step #2 you allow bits to overlap, you often won't even get as many 1-bits as the t
picked in step #1.
###Generating t
bits correctly###
From your comment, it seems like you intended to generate t
1-bits, where t
could later be configurable. The way to do that properly would be:
- Generate
t
1-bits and the rest 0-bits. - Shuffle the vector (for example using a Fisher-Yates shuffle).