c# - Uniform random numbers to simulate with ten decimal places -
i'm tring run specific simulation, have code implemented result not 1 i'm expecting, need generate random uniform(ranged 0 1) numbers 10 decimal places (in order convert in other distribution). example: 0,0345637897, 0,3445627876, 0,9776428487
this code:
double next = r.next(1000000000, 9999999999); return double.parse(string.format("0.{0}", next));
this should enough:
double v = math.round(myrandom.nextdouble(), 10);
the difference between 0.123
, 0.1230000000
matter of formatting, see answer @samiam.
after edit:
double next = r.next(1000000000, 9999999999); return double.parse(string.format("0.{0}", next));
this getting integer between 1000000000 , 9999999999 , uses default culture convert double (in 0 ... 1.0 range).
since seem use comma (,
) decimal separator, @ least use
return double.parse(string.format("0.{0}", next), cultureinfo.invariant);
Comments
Post a Comment