Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: runtime/lib/math_patch.dart

Issue 200483003: - Do not rely on time to seed the default PRNG. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "dart:typed_data"; 5 import "dart:typed_data";
6 6
7 // A VM patch of the dart:math library. 7 // A VM patch of the dart:math library.
8 8
9 // If [x] is an [int] and [exponent] is a non-negative [int], the result is 9 // If [x] is an [int] and [exponent] is a non-negative [int], the result is
10 // an [int], otherwise the result is a [double]. 10 // an [int], otherwise the result is a [double].
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // Constants used by the algorithm or masking. 147 // Constants used by the algorithm or masking.
148 static const _MASK_32 = (1 << 32) - 1; 148 static const _MASK_32 = (1 << 32) - 1;
149 static const _MASK_64 = (1 << 64) - 1; 149 static const _MASK_64 = (1 << 64) - 1;
150 static const _POW2_32 = 1 << 32; 150 static const _POW2_32 = 1 << 32;
151 static const _POW2_53_D = 1.0 * (1 << 53); 151 static const _POW2_53_D = 1.0 * (1 << 53);
152 static const _POW2_27_D = 1.0 * (1 << 27); 152 static const _POW2_27_D = 1.0 * (1 << 27);
153 153
154 static const _A = 0xffffda61; 154 static const _A = 0xffffda61;
155 155
156 // Use a singleton Random object to get a new seed if no seed was passed. 156 // Use a singleton Random object to get a new seed if no seed was passed.
157 static var _prng = null; 157 static var _prng = new Random(_initialSeed());
siva 2014/03/17 17:46:02 This can potentially result in an overflow error w
158
159 static int _initialSeed() native "Random_initialSeed";
158 160
159 static int _nextSeed() { 161 static int _nextSeed() {
160 if (_prng == null) {
161 // TODO(iposva): Use system to get a random seed.
162 _prng = new Random(new DateTime.now().millisecondsSinceEpoch);
163 }
164 // Trigger the PRNG once to change the internal state. 162 // Trigger the PRNG once to change the internal state.
165 _prng._nextState(); 163 _prng._nextState();
166 return _prng._state[kSTATE_LO]; 164 return _prng._state[kSTATE_LO];
167 } 165 }
168 } 166 }
OLDNEW
« runtime/lib/math.cc ('K') | « runtime/lib/math.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698