Skip to content

Commit 0aee297

Browse files
committed
docs
1 parent b3b004d commit 0aee297

13 files changed

+31
-50
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
Classes that implement all-purpose, rock-solid **random number generators**.
99

1010
Library priorities:
11-
- perfect match of the numbers on all platforms
11+
- generation of identical bit-accurate numbers regardless of the platform
12+
- reproducibility of the same random results in the future
13+
- high-quality randomness
1214
- performance
13-
- quality of the numbers produced
1415

1516
Algorithms are [Xoshiro](https://prng.di.unimi.it/) for **quality** and
1617
[Xorshift](https://en.wikipedia.org/wiki/Xorshift) for **speed**.
1718

1819
# Speed
1920

20-
Generating 50 million of random numbers with AOT-compiled binary.
21+
Generating 50 million random numbers with AOT-compiled binary.
2122

2223
| Time (lower is better) | nextInt | nextDouble | nextBool |
2324
|------------------------|---------|------------|----------|
@@ -176,8 +177,8 @@ All the benchmarks on this page are from AOT-compiled binaries running on AMD A9
176177

177178
The library has been thoroughly **tested to match reference numbers** generated by C algorithms. The
178179
sources in C are taken directly from scientific publications or the reference implementations by the inventors of the algorithms. The Xorshift128+ results are also matched to reference
179-
values from [JavaScript xorshift library](https://github.com/AndreasMadsen/xorshift), that tested
180+
values from [JavaScript xorshift library](https://github.com/AndreasMadsen/xorshift), which tested
180181
the 128+ similarly.
181182

182-
Testing is done in the GitHub Actions cloud on **Windows**, **Ubuntu** and **macOS** in **VM** and **Node.js** modes.
183+
Testing is done in the GitHub Actions cloud on **Windows**, **Ubuntu**, and **macOS** in **VM** and **Node.js** modes.
183184

lib/src/00_errors.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class Unsupported64Error extends UnsupportedError {
2-
Unsupported64Error() : super("Not a 64 bit system.");
3-
}
2+
Unsupported64Error() : super('Not a 64 bit system.');
3+
}

lib/src/00_ints.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44

55
// declaring int64 as BigInt to avoid JavaScript compilation errors
6-
final int INT64_LOWER_7_BYTES = BigInt.parse("0x00FFFFFFFFFFFFFF").toInt();
7-
final int INT64_MAX_POSITIVE = BigInt.parse("0x7FFFFFFFFFFFFFFF").toInt();
6+
final int INT64_LOWER_7_BYTES = int.parse('0x00FFFFFFFFFFFFFF');
7+
final int INT64_MAX_POSITIVE = int.parse('0x7FFFFFFFFFFFFFFF');
88
const UINT32_MAX = 0xFFFFFFFF;
99
const INT64_SUPPORTED = (1<<62) > (1<<61); // true for 64-bit systems (not for JS)
1010

lib/src/10_random_base.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
import 'dart:math';
6+
67
import '00_ints.dart';
78

89
abstract class RandomBase32 implements Random {

lib/src/seeding.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@pragma('vm:prefer-inline')
12
int mess2to64A(int a, int b) {
23
// "The mix method was inspired by the mixing step of the lcg64_shift random engine"
34
// <https://medium.com/@jeneticsga/creating-random-seeds-with-java-3df09bd02188>
@@ -8,6 +9,7 @@ int mess2to64A(int a, int b) {
89
return c;
910
}
1011

12+
@pragma('vm:prefer-inline')
1113
int mess2to64B(int b, int a) {
1214
// Same as [mess2to64A], but with arguments swapped.
1315
var c = a^b;
@@ -17,10 +19,12 @@ int mess2to64B(int b, int a) {
1719
return c;
1820
}
1921

22+
@pragma('vm:prefer-inline')
2023
int mess2to64C(int a, int b) {
2124
return mess2to64A(a+0xb35a6012, b*0xdcde19b9);
2225
}
2326

27+
@pragma('vm:prefer-inline')
2428
int mess2to64D(int a, int b) {
2529
return mess2to64B(a+0x93999086, b*0x87b4f97a);
2630
}

lib/src/splitmix64.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// SPDX-FileCopyrightText: (c) 2021 Art Galkin <github.com/rtmigo>
22
// SPDX-License-Identifier: MIT
33

4-
import 'dart:math';
54

6-
import 'package:xrandom/src/seeding.dart';
5+
import 'package:xrandom/src/10_random_base.dart';
76

87
import '00_errors.dart';
98
import '00_ints.dart';
10-
import 'package:xrandom/src/10_random_base.dart';
119

1210
/// Random number generator based on `splitmix64` algorithm by S. Vigna (2015).
1311
/// The reference implementation in C can be found in

lib/src/xorshift128.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// SPDX-FileCopyrightText: (c) 2021 Art Galkin <github.com/rtmigo>
22
// SPDX-License-Identifier: MIT
33

4+
import 'package:xrandom/src/10_random_base.dart';
45
import 'package:xrandom/src/seeding.dart';
56

67
import '00_ints.dart';
7-
import 'package:xrandom/src/10_random_base.dart';
88

99
/// Random number generator based on `xorshift128` algorithm by G. Marsaglia (2003).
1010
/// The reference implementation in C can be found in
@@ -21,7 +21,7 @@ class Xorshift128 extends RandomBase32
2121
RangeError.checkValueInInterval(d!, 0, UINT32_MAX);
2222

2323
if (a==0 && b==0 && c==0 && d==0) {
24-
throw ArgumentError("The seed should not consist of only zeros..");
24+
throw ArgumentError('The seed should not consist of only zeros..');
2525
}
2626

2727
_a = a;
@@ -41,6 +41,7 @@ class Xorshift128 extends RandomBase32
4141
}
4242
late int _a, _b, _c, _d;
4343

44+
@override
4445
int nextInt32() {
4546

4647
// algorithm from p.5 of "Xorshift RNGs"

lib/src/xorshift128plus.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// SPDX-FileCopyrightText: (c) 2021 Art Galkin <github.com/rtmigo>
22
// SPDX-License-Identifier: MIT
33

4-
import 'package:xrandom/src/seeding.dart';
4+
import 'package:xrandom/src/10_random_base.dart';
55
import 'package:xrandom/src/splitmix64.dart';
66

77
import '00_errors.dart';
88
import '00_ints.dart';
9-
import 'package:xrandom/src/10_random_base.dart';
109

1110
/// Random number generator based on `xorshift128+` algorithm by S.Vigna (2015).
1211
/// The reference implementation in C can be found in <https://arxiv.org/abs/1404.0390> (V3).
@@ -39,6 +38,7 @@ class Xorshift128p extends RandomBase64 {
3938

4039
late int _S0, _S1;
4140

41+
@override
4242
int nextInt64() {
4343
// algorithm from "Further scramblings of Marsaglia’s xorshift generators"
4444
// by Sebastiano Vigna

lib/src/xorshift32.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44

55
import 'package:xrandom/src/10_random_base.dart';
6-
import 'package:xrandom/src/seeding.dart';
76

87
/// Random number generator based on `xorshift32` algorithm by G. Marsaglia (2003).
98
/// The reference implementation in C can be found in

lib/src/xorshift64.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// SPDX-FileCopyrightText: (c) 2021 Art Galkin <github.com/rtmigo>
22
// SPDX-License-Identifier: MIT
33

4-
import 'dart:math';
54

6-
import 'package:xrandom/src/seeding.dart';
5+
import 'package:xrandom/src/10_random_base.dart';
76
import 'package:xrandom/src/splitmix64.dart';
87

98
import '00_errors.dart';
109
import '00_ints.dart';
11-
import 'package:xrandom/src/10_random_base.dart';
1210

1311
/// Random number generator based on `xorshift64` algorithm by G. Marsaglia (2003).
1412
/// The reference implementation in C can be found in
@@ -22,7 +20,7 @@ class Xorshift64 extends RandomBase64 {
2220
}
2321
if (seed != null) {
2422
if (seed == 0) {
25-
throw RangeError("The seed must be greater than 0.");
23+
throw RangeError('The seed must be greater than 0.');
2624
}
2725
_state = seed;
2826
} else {

0 commit comments

Comments
 (0)