@@ -2,7 +2,7 @@ import * as assert from 'assert';
22import { describe , expect , test } from 'vitest' ;
33import { utils } from '../src' ;
44import { AiScriptRuntimeError } from '../src/error' ;
5- import { NUM , STR , NULL , ARR , OBJ , BOOL , TRUE , FALSE , ERROR , FN_NATIVE } from '../src/interpreter/value' ;
5+ import { NUM , STR , NULL , ARR , OBJ , BOOL , TRUE , FALSE , ERROR , FN_NATIVE } from '../src/interpreter/value' ;
66import { exe , eq } from './testutils' ;
77
88
@@ -88,7 +88,7 @@ describe('Math', () => {
8888 test . concurrent ( 'max' , async ( ) => {
8989 eq ( await exe ( "<: Math:max(-2, -3)" ) , NUM ( - 2 ) ) ;
9090 } ) ;
91-
91+
9292 /* flaky
9393 test.concurrent('rnd', async () => {
9494 const steps = 512;
@@ -158,6 +158,35 @@ describe('Math', () => {
158158 eq ( res , ARR ( [ BOOL ( true ) , BOOL ( true ) ] ) ) ;
159159 } ) ;
160160
161+ test . concurrent ( 'gen_rng number seed' , async ( ) => {
162+ // 2つのシード値から1~maxの乱数をn回生成して一致率を見る(numがシード値として指定された場合)
163+ const res = await exe ( `
164+ @test(seed1, seed2) {
165+ let n = 100
166+ let max = 100000
167+ let threshold = 0.05
168+ let random1 = Math:gen_rng(seed1)
169+ let random2 = Math:gen_rng(seed2)
170+ var same = 0
171+ for n {
172+ if random1(1, max) == random2(1, max) {
173+ same += 1
174+ }
175+ }
176+ let rate = same / n
177+ if seed1 == seed2 { rate == 1 }
178+ else { rate < threshold }
179+ }
180+ let seed1 = 3.0
181+ let seed2 = 3.0000000000000004
182+ <: [
183+ test(seed1, seed1)
184+ test(seed1, seed2)
185+ ]
186+ ` )
187+ eq ( res , ARR ( [ BOOL ( true ) , BOOL ( true ) ] ) ) ;
188+ } ) ;
189+
161190 test . concurrent ( 'gen_rng should reject when null is provided as a seed' , async ( ) => {
162191 await expect ( ( ) => exe ( 'Math:gen_rng(null)' ) ) . rejects . toThrow ( AiScriptRuntimeError ) ;
163192 } ) ;
@@ -202,7 +231,7 @@ describe('Obj', () => {
202231
203232 <: Obj:merge(o1, o2)
204233 ` ) ;
205- eq ( res , utils . jsToVal ( { a : 1 , b : 3 , c : 4 } ) ) ;
234+ eq ( res , utils . jsToVal ( { a : 1 , b : 3 , c : 4 } ) ) ;
206235 } ) ;
207236
208237 test . concurrent ( 'pick' , async ( ) => {
0 commit comments