Here's the setup:
For my Bachelor's thesis, I want to test jet algorithms used at the LHC. Basically the first step is the folowing: Given some 4-momentum
p[0] = nullvector(45.0000000000106,33.03951484238976,14.97124733712793,26.6317895033428)
I want to simulate experimental data by adding some (like, 50) randomly generated 4-vectors to the last three components in the order of 10^(-12), so that they are small (that's where the interesting physics happens), but significantly above the double float precision of 15 decimals. So the quick-and-dirty solution to that is the following:
seed=time(NULL);
srand(seed);
random=(rand()%9001)*1.0E-15;
random=random+1E-12;
printf("%.15E\n",random);
This gives me random numbers between 1E-12 and 10E-12 (=1E-11) with three decimals max, so that in "real" doubles, that gives me 15 decimals.
Now to the point: Can I store numbers in that order with more than three decimals without overstepping double float precision?
PS: Is there a better way to generate small random numbers? (This sounds like another topic ;))
The traditional method for creating floating point random numbers is to make it a range [0-1) by taking double x = (double)rand()/RAND_MAX;
- then multiply by 9001E-1
to scale your range to the 1E-12
to 1E-15
values [zero inclusive].
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