Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trying to find a fully-random number generator

I work in C and i am trying(desperately) to make a random generator that not only generates a different number every time i run the generator but also a different sequence every time i run the program.I tested almost everything i found online.I resulted in 2 good ways to make a good random generator. The first one is to use a different seed every time.But this means that i have to use a different-random seed every time,a matter that i didn't solve at first.Here is what i am trying now but it's not truly random as i want:

int myrand(int random_seed){
  random_seed = random_seed * 1103515245 +12345;   
  return (unsigned int)(random_seed / 65536) % 32768; 
                           }

Every time i call the function i increase the seed by 1.

The second way is to use time.Time changes and this is randomness.I also tried many ways to implement this.My latest try is here: Compiler error-Possible IDE error"undefined reference to gettimeofday error" but i couldn't use the gettimeofday function because i work in Windows.Also in that question i didn't get any answers.

Could anyone give help me of how i can implement a random generator(probably using time) in C working in Windows?Or should i use Unix?

like image 778
Dchris Avatar asked Dec 18 '12 17:12

Dchris


People also ask

Can you trick a random number generator?

It is possible to hack into the Random Number Generators used in casinos and other fields. But, it is a difficult venture that even the best hackers find challenging. With high-quality RNGs and security protocols, this possibility can be reduced to the minimum.

What is the formula to generate random numbers?

If we wish to generate a random number between two numbers, we can use the formula: RAND() * (b – a) + a, where a is the smallest number and b is the largest number that we wish to generate a random number for.

Can you have a truly random number?

Unfortunately, generating random numbers looks a lot easier than it really is. Indeed, it is fundamentally impossible to produce truly random numbers on any deterministic device.

Is Google random number generator truly random?

In reality, most random numbers used in computer programs are pseudo-random, which means they are generated in a predictable fashion using a mathematical formula. This is fine for many purposes, but it may not be random in the way you expect if you're used to dice rolls and lottery drawings.


1 Answers

Seed your RNG with a good source of entropy.

Under unix, use /dev/random.

Under windows, use something like CryptoAPI - Windows equivalent of /dev/random

like image 119
evil otto Avatar answered Oct 01 '22 12:10

evil otto