I need to get a sequence of bits which will represent the work of LCG in rand() function in C, but I've no idea how to do it. Found a code example which looks like this
// C program for generating a
// random number in a given range.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// Generates and prints 'count' random
// numbers in range [lower, upper].
void printRandoms(int lower, int upper,
int count)
{
int i;
for (i = 0; i < count; i++) {
int num = (rand() %
(upper - lower + 1)) + lower;
printf("%d ", num);
}
}
// Driver code
int main()
{
int lower = 0, upper = 1, count = 30;
// Use current time as
// seed for random generator
srand(time(0));
printRandoms(lower, upper, count);
return 0;
}
but I'm not sure if the sequence from this program will be an LCG binary sequence. Is there any other ways of getting bitstream from rand?
Aucun commentaire:
Enregistrer un commentaire