@@ -4,18 +4,40 @@ var common = require('../common');
44var assert = common . assert ;
55var FormData = require ( common . dir . lib + '/form_data' ) ;
66var satisfies = require ( 'semver' ) . satisfies ;
7- var predictV8Randomness = satisfies ( process . version , '^17 - ^23 ' ) && require ( 'predict-v8- randomness' ) ; // eslint-disable-line global-require
7+ var jsrp = satisfies ( process . version , '>= 17 ' ) && require ( 'js- randomness-predictor ' ) ; // eslint-disable-line global-require
88
9- var initialSequence = [
10- Math . random ( ) ,
11- Math . random ( ) ,
12- Math . random ( ) ,
13- Math . random ( ) ,
14- ] ;
15- var predictor = predictV8Randomness && new predictV8Randomness . Predictor ( initialSequence ) ;
9+ var predictor = jsrp && jsrp . node ( ) ;
10+
11+ /**
12+ * Predicts the next random outputs from the V8 engine's random number generator.
13+ *
14+ * @param {JsRandomnessPredictor } predictorInstance - The instance of the randomness predictor.
15+ * @param {number } count - The number of random outputs to predict.
16+ * @returns {Promise<number[]> } A promise that resolves with the predicted random outputs or rejects with an error.
17+ */
18+ function predictMany ( predictorInstance , count ) {
19+ return new Promise ( function ( resolve , reject ) {
20+ var outputs = [ ] ;
21+
22+ /** Recursive function to predict the next random output */
23+ function predictOne ( ) {
24+ predictorInstance . predictNext ( ) . then ( function ( nextOutput ) {
25+ outputs . push ( nextOutput ) ;
26+
27+ if ( outputs . length < count ) {
28+ predictOne ( ) ;
29+ } else {
30+ resolve ( outputs ) ;
31+ }
32+ } ) . catch ( reject ) ;
33+ }
34+
35+ predictOne ( ) ;
36+ } ) ;
37+ }
1638
1739if ( predictor ) {
18- predictor . predictNext ( 24 ) . then ( function ( next24RandomOutputs ) {
40+ predictMany ( predictor , 24 ) . then ( function ( next24RandomOutputs ) {
1941 var predictedBoundary = next24RandomOutputs
2042 . map ( function ( v ) {
2143 return Math . floor ( v * 10 ) . toString ( 16 ) ;
0 commit comments