Question subject: Pseudo Randon Number Generator code??
Posted: Sat Apr 11, 2009 2:35 am
Joined: Thu Mar 12, 2009 10:02 am Posts: 6 Has thanked: 0 time Have thanks: 0 time
Hi,
I'm trying to use a simple PRNG C program but am having problems.
Could someone please run this code and let me know if it works and post the output. It should be working perfectly but I am having trouble with my compiler. Thanks
#include<stdio.h> #include<stdint.h>
uint16_t rand16(); uint32_t rand32();
uint16_t n, userChosenValue = 0; //Change this for different seed values. uint16_t numberOfValues = 10; //Change this depending on your needs. uint32_t seed; uint32_t mlcg,p,q; uint64_t tmpseed;
int main(){
/* Calculate and print a series of 16 bit random numbers */ seed = (uint32_t)(userChosenValue + 1);
printf("16 Bit:\n\n"); for (n=0;n<numberOfValues;n++){ printf("%.4x\n",rand16()); }
/* Calculate and print a series of 32 bit random numbers */ seed = (uint32_t)(userChosenValue + 1);
printf("\n\n32 Bit:\n\n"); for (n=0;n<numberOfValues;n++){ printf("%.8x\t\t\n",rand32()); }
return 0; }
/* Return the next 32 bit random number */ uint32_t rand32() {