I am in a coding environment where I only have access to some most basic c functions. #include'ing other lib is not feasible.
In this environment, I can call rand() which gives me a random number between 0 to 32767 inclusively(I think) in my environment. Is the following code the right logic to get a larger random number that is evenly distributed like/as rand()?
rnum = rand() * (32767 + 1) + rand();
rnum = (rand() << 15) | rand()
might be faster, but if you need good quality random numbers you should look for an external library. Built-in random functions are generally adequate only for the simplest applications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With