File tree Expand file tree Collapse file tree 2 files changed +124
-107
lines changed
Expand file tree Collapse file tree 2 files changed +124
-107
lines changed Original file line number Diff line number Diff line change 11// randomEngine.js - moteur d'aléatoire avancé + bruit
22
33class RandomEngine {
4- constructor ( seed = Date . now ( ) ) {
4+ constructor ( seed = Date . now ( ) + Math . random ( ) * 1000 ) {
55 this . seed = seed ;
66 this . rand = this . mulberry32 ( seed ) ;
77 this . generateGradientTable ( ) ;
@@ -109,7 +109,24 @@ class RandomEngine {
109109 static cryptoInt ( min , max ) {
110110 const range = max - min + 1 ;
111111 const rand = new Uint32Array ( 1 ) ;
112- crypto . getRandomValues ( rand ) ;
112+
113+ // Support cross-platform crypto
114+ if ( typeof crypto !== 'undefined' && crypto . getRandomValues ) {
115+ crypto . getRandomValues ( rand ) ;
116+ } else if ( typeof require !== 'undefined' ) {
117+ try {
118+ const crypto = require ( 'crypto' ) ;
119+ const buffer = crypto . randomBytes ( 4 ) ;
120+ rand [ 0 ] = buffer . readUInt32BE ( 0 ) ;
121+ } catch ( e ) {
122+ // Fallback pour les environnements sans crypto
123+ rand [ 0 ] = Math . floor ( Math . random ( ) * 4294967296 ) ;
124+ }
125+ } else {
126+ // Fallback ultime
127+ rand [ 0 ] = Math . floor ( Math . random ( ) * 4294967296 ) ;
128+ }
129+
113130 return min + ( rand [ 0 ] % range ) ;
114131 }
115132
You can’t perform that action at this time.
0 commit comments