Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
dart-lang
sdk
runtime
vm
random.h
Go to the documentation of this file.
1
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2
// for details. All rights reserved. Use of this source code is governed by a
3
// BSD-style license that can be found in the LICENSE file.
4
5
#ifndef RUNTIME_VM_RANDOM_H_
6
#define RUNTIME_VM_RANDOM_H_
7
8
#include <atomic>
9
10
#include "
vm/allocation.h
"
11
#include "
vm/flags.h
"
12
#include "
vm/globals.h
"
13
14
namespace
dart
{
15
16
DECLARE_FLAG
(uint64_t, random_seed);
17
18
class
Random
{
19
public
:
20
Random
();
21
// Seed must be non-zero.
22
explicit
Random
(uint64_t seed);
23
~Random
();
24
25
uint32_t
NextUInt32
();
26
uint64_t
NextUInt64
() {
27
return
(
static_cast<
uint64_t
>
(
NextUInt32
()) << 32) |
28
static_cast<
uint64_t
>
(
NextUInt32
());
29
}
30
31
// Returns a random number that's a valid JS integer.
32
//
33
// All IDs that can be returned over the service protocol should be
34
// representable as JS integers and should be generated using this method.
35
//
36
// See https://github.com/dart-lang/sdk/issues/53081.
37
uint64_t
NextJSInt
() {
38
// Number.MAX_SAFE_INTEGER (2 ^ 53 - 1)
39
const
uint64_t kMaxJsInt = 0x1FFFFFFFFFFFFF;
40
return
NextUInt64
() & kMaxJsInt;
41
}
42
43
static
uint64_t
GlobalNextUInt64
();
44
static
void
Init
();
45
static
void
Cleanup
();
46
47
// Generates a uniform random variable in the range [0,1].
48
double
NextDouble
();
49
50
private
:
51
uint64_t NextState();
52
void
Initialize(uint64_t seed);
53
54
std::atomic<uint64_t> _state;
55
56
DISALLOW_COPY_AND_ASSIGN
(
Random
);
57
};
58
59
}
// namespace dart
60
61
#endif
// RUNTIME_VM_RANDOM_H_
dart::Random
Definition
random.h:18
dart::Random::Random
Random()
Definition
random.cc:17
dart::Random::GlobalNextUInt64
static uint64_t GlobalNextUInt64()
Definition
random.cc:95
dart::Random::Cleanup
static void Cleanup()
Definition
random.cc:88
dart::Random::NextUInt64
uint64_t NextUInt64()
Definition
random.h:26
dart::Random::Init
static void Init()
Definition
random.cc:81
dart::Random::NextDouble
double NextDouble()
Definition
random.cc:100
dart::Random::NextUInt32
uint32_t NextUInt32()
Definition
random.cc:73
dart::Random::~Random
~Random()
Definition
random.cc:49
dart::Random::NextJSInt
uint64_t NextJSInt()
Definition
random.h:37
flags.h
DECLARE_FLAG
#define DECLARE_FLAG(type, name)
Definition
flags.h:14
dart
Definition
dart_vm.cc:33
DISALLOW_COPY_AND_ASSIGN
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition
globals.h:581
allocation.h
globals.h
Generated on Fri Apr 26 2024 06:15:17 for Flutter Engine by
1.9.8