mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 21:51:40 +03:00
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:
parent
54ea896afc
commit
945f9510b1
1 changed files with 10 additions and 3 deletions
13
std/random.d
13
std/random.d
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue