1+ import { randomIntegerBetween } from "@std/random/integer-between" ;
12import { shuffle } from "@std/random/shuffle" ;
23import { IterableResult , ResultError } from "../compound.ts" ;
34import { parser } from "../parser/parser.ts" ;
@@ -6,7 +7,7 @@ import * as EnglishComposer from "./composer.ts";
67import { fixMultipleSentences } from "./fixer.ts" ;
78import { multipleSentences } from "./sentence.ts" ;
89
9- const RANDOMIZATION_LIMIT = 25248 ;
10+ const RANDOMIZATION_LIMIT = 20_000 ;
1011
1112export function translate ( tokiPona : string ) : IterableResult < string > {
1213 return new IterableResult ( [ ] , function * ( ) {
@@ -20,16 +21,15 @@ export function translate(tokiPona: string): IterableResult<string> {
2021 const unique : Set < string > = new Set ( ) ;
2122 if ( settings . randomize ) {
2223 for ( const result of iterableResult ) {
23- if ( unique . size > RANDOMIZATION_LIMIT ) {
24- yield {
25- type : "error" ,
26- error : new ResultError ( "too many output to shuffle" ) ,
27- } ;
28- return ;
29- }
3024 switch ( result . type ) {
3125 case "value" :
3226 unique . add ( result . value ) ;
27+ if ( unique . size > RANDOMIZATION_LIMIT ) {
28+ const sample = [ ...unique ] ;
29+ const value = sample [ randomIntegerBetween ( 0 , sample . length ) ] ;
30+ unique . delete ( value ) ;
31+ yield { type : "value" , value } ;
32+ }
3333 break ;
3434 case "error" :
3535 aggregateErrors . push ( result . error ) ;
0 commit comments