-
-
Notifications
You must be signed in to change notification settings - Fork 672
Add an option to select how to seed random() #1080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This will probably fail somewhere due to randomness in fixtures. Also makes me wonder if we should remove |
import * as JSMath from "./bindings/Math"; | ||
import * as JSDate from "./bindings/Date"; | ||
import * as wasi from "./bindings/wasi_snapshot"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's something wrong here in that "./bindings/wasi"
does not work. Can't find the symbols. Thought we had fixed those export *
/ import *
problems :(
@@ -1,4 +1,10 @@ | |||
/// <reference path="./util/seedrandom.d.ts" /> | |||
|
|||
import { ArrayBufferView } from "./arraybuffer"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By doing that, we can changetype<ArrayBufferView>
anything accessing .dataStart
, getting rid of TS syntax highlighting issues.
let value = Long.fromBits(Math.random() * 0xffffffff, Math.random() * 0xffffffff, true); | ||
assemblyscript.setGlobalAlias(compilerOptions, "ASC_SEEDRANDOM_LOW", (value.low >>> 0).toString()); | ||
assemblyscript.setGlobalAlias(compilerOptions, "ASC_SEEDRANDOM_HIGH", (value.high >>> 0).toString()); | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems use Long.fromBits
here is unnecessary. What about:
const low = Math.random() * 0xffffffff >>> 0;
const high = Math.random() * 0xffffffff >>> 0;
assemblyscript.setGlobalAlias(compilerOptions, "ASC_SEEDRANDOM_LOW", low.toString());
assemblyscript.setGlobalAlias(compilerOptions, "ASC_SEEDRANDOM_HIGH", high.toString());
Superseded by #1159 which adds a programmatic mechanism instead. |
This adds an option to asc to select how to seed native math's
random()
function, currently supporting: