4 ms·
Btw you could speedup your AssemblyScript code: https://bit.ly/2FW2iyN https://bit.ly/2FW2iyN ``` const eps: f64 = 2.3283064365386963e-10; const m: u64 = 63641
by maxgraey 6y ago
Btw you could speedup your AssemblyScript code:
https://bit.ly/2FW2iyN https://bit.ly/2FW2iyN
```
const eps: f64 = 2.3283064365386963e-10;
const m: u64 = 6364136223846793005;
const inc: u64 = 1442695040888963407;
let state: u64 = 1;
export function random(): f64 {
let oldstate = state * 6364136223846793005 + 1442695040888963407;
state = oldstate;
const xorshifted = u32(((oldstate >>> 18) ^ oldstate) >> 27);
const out_int = rotr(xorshifted, u32(oldstate >> 59));
return eps * out_int;
}
```
I recommend return f64 instead f32. This has slightly faster interop
- vanderZwan 6y agoThanks for the tips! (also, as you might have noticed, HN doesn't support MD proper. To get code blocks you have to indent it with four spaces) const eps: f64 = 2.3283064365386963e-10; const m: u64 = 6364136223846793005; const inc: u64 = 1442695040888963407; let state: u64 = 1; export function random(): f64 { let oldstate = state * 6364136223846793005 + 1442695040888963407; state = oldstate; const xorshifted = u32(((oldstate >>> 18) ^ oldstate) >> 27); const out_int = rotr(xorshifted, u32(oldstate >> 59)); return eps * out_int; }
- maxgraey 6y ago> To get code blocks you have to indent it with four spaces I'll keep that in mind in next time. Thanks for the tip!
- chrismorgan 6y ago(Technical note: two spaces of indentation is sufficient. Note also how the common leading spaces are not removed.)
- vanderZwan 6y agoAh, thank you!