Home > other >  Newbie on the road, want to try the Python called js script, but do not achieve output information,
Newbie on the road, want to try the Python called js script, but do not achieve output information,

Time:04-23

The import execjs

CTX=execjs.com running (" ", "

Var MersenneTwister=function (seed) {if (seed==undefined) {seed=new Date (). The getTime (); }
This. N=624; This. M=397; This. MATRIX_A=0 x9908b0df; This. UPPER_MASK=0 x80000000; This. LOWER_MASK=0 x7fffffff; This. Mt=new Array (this. N); This. Mti=this. N + 1; Enclosing init_genrand (seed); }
MersenneTwister. Prototype. Init_genrand=function (s) {this. Mt [0]=s>> 0; For (enclosing mti=1; This. Mti 30); This. Mt [this mti]=(((((s& 0 xffff0000) & gt;> 16) * 1812433253) & lt; <16) + (s& 0 x0000ffff) * 1812433253)
+ this. Mti; This. Mt [this mti] & gt;>=0; }}
MersenneTwister. Prototype. Init_by_array=function (init_key key_length) {var I, j, k; Enclosing init_genrand (19650218); i=1; j=0; K=(enclosing N> Key_length? This. N: key_length); for(; k; K -) {var s=this. Mt [I - 1) ^ (enclosing mt] [I - 1 & gt;> 30)
This. Mt [I]=(enclosing mt [I] ^ (((((s& 0 xffff0000) & gt;> 16) * 1664525) & lt; <16) + ((s& 0 x0000ffff) * 1664525)))
+ + init_key [j] j; This. Mt [I] & gt;>=0; i++; j++; If (i>=this. N) {this. Mt [0]=this. Mt [this. N - 1); i=1; }
If (j> J=0=key_length); }
For (k=this. N - 1; k; K -) {var s=this. Mt [I - 1) ^ (enclosing mt] [I - 1 & gt;> 30); This. Mt [I]=(enclosing mt [I] ^ (((((s& 0 xffff0000) & gt;> 16) * 1566083941) & lt; <16) + (s& 0 x0000ffff) * 1566083941))
-i; This. Mt [I] & gt;>=0; i++; If (i>=this. N) {this. Mt [0]=this. Mt [this. N - 1); i=1; }}
This. Mt [0]=0 x80000000; }
MersenneTwister. Prototype. Genrand_int32=function () {var y; Var mag01=new Array (0 x0, enclosing MATRIX_A); If (this. Mti>=this. N) {var kk; If (this. Mti==this. N + 1)
Enclosing init_genrand (5489); For (kk=0; Kk> 1) ^ mag01 [y& 0 x1]; }
for(; Kk> 1) ^ mag01 [y& 0 x1]; }
Y=(enclosing mt [this] N - 1 & amp; Enclosing UPPER_MASK) | (enclosing mt [0] & amp; Enclosing LOWER_MASK); This. Mt [this] N - 1=this. Mt [this. M - 1) ^ (y>> 1) ^ mag01 [y& 0 x1]; This. The mti=0; }
Y=this. Mt [this mti++]; Y ^=(y>> 11); Y ^=(y<7) & amp; 0 x9d2c5680; Y ^=(y<15) & amp; 0 xefc60000; Y ^=(y>> 18); Return y>> 0; }
MersenneTwister. Prototype. Genrand_int31=function () {return (enclosing genrand_int32 () & gt;> 1); }
MersenneTwister. Prototype. Genrand_real1=function () {return enclosing genrand_int32 () * (1.0/4294967295.0); }
MersenneTwister. Prototype. The random=function () {return enclosing genrand_int32 () * (1.0/4294967296.0); }
MersenneTwister. Prototype. Genrand_real3=function () {return (enclosing genrand_int32 () + 0.5) * (1.0/4294967296.0); }
MersenneTwister. Prototype. Genrand_res53=function () {var a=this. Genrand_int32 () & gt;> 5, b=this. Genrand_int32 () & gt;> 6; Return (a + b) * 67108864.0 * (1.0/9007199254740992.0); }
//$(document). Ready (function () {
//interface event interface to remove here also want to comment out or delete
//$(' # randomGenerate). Click (randomMethod);

//variable definition
Var randomCount=20;//set number
Var randomMaximum=100;//Max
Var randomMinimum=1;//the minimum
Var randomType="unique";//select whether it is the only random number: unique only | open casually


//generates random number method
The function randomMethod () {

Var mTwister=new MersenneTwister ();
Var randomNumbers=new Array ();
For (
Var I=0;
I & lt; The parseInt (randomCount);
I++
) {
Var number=(Math. Round (mTwister. Random () * (parseInt (randomMaximum) - parseInt (randomMinimum))) + parseInt (randomMinimum));
Var found=false;
For (
Var j=0;
J & lt; RandomNumbers. Length;
J++
) {
If (
RandomNumbers [j]==number
) {
Found=true;
break;
}
}
If (
Found==true & amp; &
RandomType=='unique'
) {
i--;
} else {
RandomNumbers [I]=number;
}
}
//render to interface interface operation removed here also want to comment out or delete
//$(' # randomNumbers). The HTML (");
Var tempArr=[];
For (
Var I=0;
I & lt; RandomNumbers. Length;
I++
) {
TempArr. Push (randomNumbers [I]);

//render to interface interface operation removed here also want to comment out or delete
//$(' # randomNumbers). The HTML ($(' # randomNumbers). The HTML () + (I==0? "' : ') + '& lt; B> '+ randomNumbers [I] +' & lt;/b> ');

}


The console. The log (tempArr);

The console. The log (tempArr. Join (", "));

}



//);
RandomMethod ();


"" ")

Print (CTX) call (' randomMethod))

CodePudding user response:

Looked at roughly, return value function without writing

==

Add a return tempArr js
  • Related