Forum Discussion
Altera_Forum
Honored Contributor
14 years agoGenerate a random number with C
Hi, i would like to know how to generate a random number by using C. I wrote the following code :
srand(time(NULL));
int x = rand()%(4-1)+1;
printf("%d", x);
However, the generate...
Altera_Forum
Honored Contributor
14 years agoIf you don't need a very good random number (and rand() doesn't give you one of those - especially seeded from time()), and you code isn't running a really well determined time after fpga reset, you might get a good enough number by having counted the clocks since reset and using that instead.