Skip to content

Commit

Permalink
0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rtmigo committed Mar 21, 2021
1 parent 367c463 commit de50449
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.6.1

- Updated documentation

- Minor improvements

# 0.6.0

- Tests have been removed from the pub.dev package to reduce the size
Expand Down
2 changes: 2 additions & 0 deletions benchmark/bin/benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ int measureTime(Random r, DoWhat dbl) {

final sw = Stopwatch()..start();

//bool is32 = (r is Xorshift128p);

const N = NUM_ITEMS_PER_EXPERIMENT;

switch (dbl) {
Expand Down
34 changes: 34 additions & 0 deletions lib/src/21_base32.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ double doornikNextFloat(int u32) {
return u32.uint32_to_int32() * M_RAN_INVM32 + 0.5;
}

/// An abstract base class for all generators in the library,
/// based on algorithms that generate either 32-bit or 64-bit integers.
///
/// This class provides conversion options between the returned value types,
/// but does not specify how exactly we get the original integer random number.
///
/// If the output of the algorithm is a 32-bit integer, then the generator inherits
/// directly from [RandomBase32]. If the output of the algorithm is a 64-bit integer,
/// then the generator inherits from [RandomBase64], that overloads some of the
/// [RandomBase32] methods.
///
/// Only generators inherited from [RandomBase32], but not from [RandomBase64],
/// can work in JavaScript. However, the mere fact of inheriting from [RandomBase32]
/// is not synonymous with JavaScript compatibility. For example, the [Mulberry32]
/// class is based on an algorithm that generates 32-bit integers and inherits from
/// [RandomBase32]. But the algorithm requires 64-bit support, which is not
/// available in JavaScript.
abstract class RandomBase32 implements Random {
/// Generates a non-negative random integer uniformly distributed in the range
/// from 0 to 0xFFFFFFFF, both inclusive.
Expand Down Expand Up @@ -88,6 +105,23 @@ abstract class RandomBase32 implements Random {
return nextRaw32().uint32_to_int32() * M_RAN_INVM32 + 0.5;
}

/// Generates a random floating point value uniformly distributed
/// in the range from 0.0, inclusive, to 1.0, exclusive.
///
/// The results of this method exactly repeat the numbers usually generated
/// by algorithms in C99 or C++. For example, this allows you to accurately
/// reproduce the values of the generator used in the Chrome browser.
///
/// In C99, the type conversion is described by S. Vigna as follows:
///
/// ```
/// static inline double to_double(uint64_t x) {
/// const union { uint64_t i; double d; } u = {
/// .i = UINT64_C(0x3FF) << 52 | x >> 12
/// };
/// return u.d - 1.0;
/// }
/// ```
@override
double nextDouble() {
return nextRaw32() * 2.3283064365386963e-10 + (nextRaw32() >> 12) * 2.220446049250313e-16;
Expand Down
16 changes: 8 additions & 8 deletions lib/src/21_base64.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// SPDX-FileCopyrightText: (c) 2021 Art Galkin <github.com/rtmigo>
// SPDX-License-Identifier: MIT


import '00_ints.dart';
import '21_base32.dart';



/// An abstract base class for generators based on algorithms that output 64-bit integers.
///
/// Overrides some converting methods for cases when 64-bit integers should be handled
/// differently than 32-bit ones.
///
/// Instances of this class can work in Dart Native and VM, but not JavaScript.
abstract class RandomBase64 extends RandomBase32 {
/// Generates a non-negative random integer uniformly distributed in the range
/// from 0 to 2^64-1, both inclusive.
Expand All @@ -23,9 +26,7 @@ abstract class RandomBase64 extends RandomBase32 {
/// the upper 32 bits, and then the lower 32 bits of the generated numbers.
@override
int nextRaw32() {

if (!_split64_charged) {

_split64 = this.nextRaw64();
_split64_charged = true;

Expand All @@ -48,8 +49,6 @@ abstract class RandomBase64 extends RandomBase32 {
bool _split64_charged = false;
int _split64 = 0;



/// Generates a non-negative random floating point value uniformly distributed
/// in the range from 0.0, inclusive, to 1.0, exclusive.
///
Expand Down Expand Up @@ -113,7 +112,8 @@ abstract class RandomBase64 extends RandomBase32 {
/// }
/// ```
double nextDoubleBitcast() {
return super.nextDouble();
// this is the same as RandomBase32.nextDouble()
return nextRaw32() * 2.3283064365386963e-10 + (nextRaw32() >> 12) * 2.220446049250313e-16;
//return nextRaw32() * 2.3283064365386963e-10 + (nextRaw32() >> 12) * 2.220446049250313e-16;
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: xrandom
description: "Random number generators library focused on the consistency,
performance and reproducibility"
version: 0.6.0
version: 0.6.1
homepage: https://github.com/rtmigo/xrandom

environment:
Expand Down

0 comments on commit de50449

Please sign in to comment.