Just occurred to me a brilliant way to grab random values, I've tested a few times just now and it seems to be a usable option even for security, at least to me anyways:
Code:
#include <limits.h>
#include <malloc.h>
#include <time.h>
long mcc_rnd( long *seed, long min, long max ) {
unsigned char *tmp = malloc(1);
/* Initial ranom value */
long val = time(NULL) + ((ptrdiff_t)tmp), _seed = 1;
if ( !seed ) seed = &seed;
if ( *seed == 0 ) *seed = 1;
/* Counter possible divide by 0 situation */
val %= *seed;
val *= clock();
free(tmp);
*seed <<= 1;
return (val > max) ? max : (val < min ? min : val);
}
int main() {
int i;
long seed = 1;
for ( i = 0; i < 100; ++i ) {
(void)printf( "%ld\n", mcc_rnd( &seed, LONG_MIN,LONG_MAX) );
}
}
A real program will no doubt call malloc & co often providing a greater randomness than already provided, the time() and clock() calls help randomize in between those calls and the seed is for utilizing a change in magnitude while min & max are there to restrain the result
Go ahead and give it a try with and without a seed