@@ -10,6 +10,24 @@ part of dart.math;
10
10
/// not suitable for cryptographic purposes.
11
11
///
12
12
/// Use the [Random.secure] () constructor for cryptographic purposes.
13
+ ///
14
+ /// To create a non-negative random integer uniformly distributed in the range
15
+ /// from 0, inclusive, to max, exclusive, use [nextInt(int max)] .
16
+ /// ```dart
17
+ /// var intValue = Random().nextInt(10); // Value is >= 0 and < 10.
18
+ /// intValue = Random().nextInt(100) + 50; // Value is >= 50 and < 150.
19
+ /// ```
20
+ /// To create a non-negative random floating point value uniformly distributed
21
+ /// in the range from 0.0, inclusive, to 1.0, exclusive, use [nextDouble] .
22
+ /// ```dart
23
+ /// var doubleValue = Random().nextDouble(); // Value is >= 0.0 and < 1.0.
24
+ /// doubleValue = Random().nextDouble() * 256; // Value is >= 0.0 and < 256.0.
25
+ /// ```
26
+ /// To create a random Boolean value, use [nextBool] .
27
+ /// ```dart
28
+ /// var boolValue = Random().nextBool(); // true or false, with equal chance.
29
+ /// ```
30
+ ///
13
31
abstract class Random {
14
32
/// Creates a random number generator.
15
33
///
@@ -29,12 +47,29 @@ abstract class Random {
29
47
///
30
48
/// Implementation note: The default implementation supports [max] values
31
49
/// between 1 and (1<<32) inclusive.
50
+ ///
51
+ /// Example:
52
+ /// ```dart
53
+ /// var intValue = Random().nextInt(10); // Value is >= 0 and < 10.
54
+ /// intValue = Random().nextInt(100) + 50; // Value is >= 50 and < 150.
55
+ /// ```
32
56
int nextInt (int max);
33
57
34
58
/// Generates a non-negative random floating point value uniformly distributed
35
59
/// in the range from 0.0, inclusive, to 1.0, exclusive.
60
+ ///
61
+ /// Example:
62
+ /// ```dart
63
+ /// var doubleValue = Random().nextDouble(); // Value is >= 0.0 and < 1.0.
64
+ /// doubleValue = Random().nextDouble() * 256; // Value is >= 0.0 and < 256.0.
65
+ /// ```
36
66
double nextDouble ();
37
67
38
68
/// Generates a random boolean value.
69
+ ///
70
+ /// Example:
71
+ /// ```dart
72
+ /// var boolValue = Random().nextBool(); // true or false, with equal chance.
73
+ /// ```
39
74
bool nextBool ();
40
75
}
0 commit comments