Update random.d

Demonstrate basic usage of uniform01. The existing example is confusing because it mixes in feqrel without any explanation, as you can see from [this question on the forum](https://forum.dlang.org/post/utjsiocsbearbenpaiut@forum.dlang.org).
This commit is contained in:
Lance Bachmeier 2020-08-10 10:09:39 -05:00 committed by GitHub
parent 54ea896afc
commit 945f9510b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2603,9 +2603,16 @@ do
import std.math : feqrel;
auto rnd = MinstdRand0(42);
assert(rnd.uniform01.feqrel(0.000328707) > 20);
assert(rnd.uniform01!float.feqrel(0.524587) > 20);
// Generate random numbers in the range in the range [0, 1)
auto u1 = uniform01(rnd);
auto u2 = rnd.uniform01!float;
assert(u1 >= 0 && u1 < 1);
assert(u2 >= 0 && u2 < 1);
// Confirm that their values are 0.000328707 and 0.524587
assert(u1.feqrel(0.000328707) > 20);
assert(u2.feqrel(0.524587) > 20);
}
@safe @nogc unittest