-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
Math:gen_rng のアルゴリズムがchacha20のとき、 seed を null にすることができ、シードがランダムな乱数生成器が生成される。
aiscript/src/interpreter/lib/math.ts
Line 221 in d6106b8
| if (seed.type !== 'num' && seed.type !== 'str' && seed.type !== 'null') throw new AiScriptRuntimeError('`seed` must be either number or string if specified.'); |
aiscript/src/utils/random/genrng.ts
Lines 32 to 40 in d6106b8
| if (!seed || seed.type !== 'num' && seed.type !== 'str' && seed.type !== 'null') return NULL; | |
| let actualSeed : Uint8Array | undefined = undefined; | |
| if (seed.type === 'num') | |
| { | |
| actualSeed = new Uint8Array(await crypto.subtle.digest('SHA-384', new Uint8Array(new Float64Array([seed.value])))); | |
| } else if (seed.type === 'str') { | |
| actualSeed = new Uint8Array(await crypto.subtle.digest('SHA-384', new Uint8Array(textEncoder.encode(seed.value)))); | |
| } | |
| const rng = new ChaCha20(actualSeed); |
aiscript/src/utils/random/chacha20.ts
Lines 60 to 62 in d6106b8
| if (typeof seed === 'undefined') { | |
| keynonce = crypto.getRandomValues(new Uint8Array(keyNonceBytes)); | |
| } else { |
他のアルゴリズムの場合も seed を null にすることができるが、エラーは発生せず null が返される。
aiscript/src/utils/random/genrng.ts
Lines 9 to 10 in d6106b8
| if (!seed || seed.type !== 'num' && seed.type !== 'str') return NULL; | |
| const rng = seedrandom(seed.value.toString()); |
aiscript/src/utils/random/genrng.ts
Lines 20 to 21 in d6106b8
| if (!seed || seed.type !== 'num' && seed.type !== 'str') return NULL; | |
| const rng = new SeedRandomWrapper(seed.value); |
例
<: Math:gen_rng(null)()
<: Math:gen_rng(null)()
<: Math:gen_rng(null, {algorithm: "rc4_legacy"})
<: Math:gen_rng(null, {algorithm: "rc4"})
出力
0.21390153769277456
0.15832915539986403
null
null
Metadata
Metadata
Assignees
Labels
No labels