This is a C Program to genrate random numbers using Naor-Reingold random function.
Here is source code of the C Program to Implement Naor-Reingold Pseudo Random Function. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char **argv) {
int p = 7, l = 3, g = 2, n = 4, x, i, j, k;
int mul = 1;
int a[] = { 1, 2, 2, 1 };
int bin[4];
printf("The Random numbers are: ");
for (i = 0; i < 10; i++) {
x = rand() % 16;
for (j = 3; j >= 0; j--) {
bin[j] = x % 2;
x /= 2;
}
for (k = 0; k < 4; k++)
mul *= pow(a[k], bin[k]);
printf("%f ", pow(g, mul));
}
}
Output:
$ gcc Naor-Reingold.c $ ./a.out The Random numbers are: 2.000000 4.000000 16.000000 4.000000 2.000000 4.000000 16.000000 16.000000 4.000000 2.000000
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data Structures and Algorithms.
Related Posts:
- Watch Advanced C Programming Videos
- Practice BCA MCQs
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Check C Books