Oops.. It was a test! :)
- int astart,aend,bstart,bend,cstart,cend,
- dstart,dend,estart,eend,fstart,fend,gstart,gend,
- hstart,hend;
- long x;
- void setup() {
- noLoop();
- println("Hold on, calculating!");
- print("Xor fast random starting!");
- x=System.nanoTime();
- astart=millis();
- for (int i=0;i<2147483646/100;i++) {
- x ^= (x << 21);
- x ^= (x >>> 35);
- x ^= (x << 4);
- randomSeed(x);
- int y=(int)random(0,100);
- if ( ( i % 1000000 ) == 0 ) print(".");
- }
- aend=millis();
- println("done");
- print("Processing nextInt random starting!");
- Random random = new Random();
- bstart=millis();
- for (int i=0;i<2147483646/100;i++) {
- randomSeed( System.nanoTime() );
- random.nextInt(100);
- if ( ( i % 1000000 ) == 0 ) print(".");
- }
- bend=millis();
- println("done");
- print("Processing normal random starting!");
- cstart=millis();
- for (int i=0;i<2147483646/100;i++) {
- randomSeed( System.nanoTime() );
- int y=(int)random(0, 100);
- if ( ( i % 1000000 ) == 0 ) print(".");
- }
- cend=millis();
- println("done");
- print("Java normal random starting!");
- dstart=millis();
- for (int i=0;i<2147483646/100;i++) {
- random.setSeed( System.nanoTime() );
- int y=(int)Math.random()*99+1;
- if ( ( i % 1000000 ) == 0 ) print(".");
- }
- dend=millis();
- println("done");
- print("Testing system.nanotime() starting!");
- estart=millis();
- for (int i=0;i<2147483646/100;i++) {
- x=System.nanoTime();
- if ( ( i % 1000000 ) == 0 ) print(".");
- }
- eend=millis();
- println("done");
- print("Testing hour() + second() + millis() starting!");
- fstart=millis();
- for (int i=0;i<2147483646/100;i++) {
- x=hour() + second() + millis();
- if ( ( i % 1000000 ) == 0 ) print(".");
- }
- fend=millis();
- println("done");
- print("Xor truly random starting!");
- gstart=millis();
- for (int i=0;i<2147483646/100;i++) {
- x=System.nanoTime();
- x ^= (x << 21);
- x ^= (x >>> 35);
- x ^= (x << 4);
- randomSeed(x);
- int y=(int)random(0,100);
- if ( ( i % 1000000 ) == 0 ) print(".");
- }
- gend=millis();
- println("done");
- print("Xor cheat random starting!");
- x=System.nanoTime();
- hstart=millis();
- for (int i=0;i<2147483646/100;i++) {
- x ^= (x << 21);
- x ^= (x >>> 35);
- x ^= (x << 4);
- randomSeed(x);
- int y=(int)random(0,100);
- if ( ( i % 1000000 ) == 0 ) {
- print(".");
- x=System.nanoTime();
- }
- }
- hend=millis();
- println("done");
- }
- void draw() {
- println("Ready! The results are :");
- println("Xor fast random : "+(aend-astart)+ " millis");
- println("Processing nextInt random : "+(bend-bstart)+ " millis");
- println("Processing normal random : "+(cend-cstart)+ " millis");
- println("Java normal random : "+(dend-dstart)+ " millis");
- println("system.nanotime() : "+(eend-estart)+ " millis");
- println("hour() + second() + millis() : "+(fend-fstart)+ " millis");
- println("Xor truly random : "+(gend-gstart)+ " millis");
- println("Xor cheat random : "+(hend-hstart)+ " millis");
- }
Hold on, calculating!
Xor fast random starting!......................done
Processing nextInt random starting!......................done
Processing normal random starting!......................done
Java normal random starting!......................done
Testing system.nanotime() starting!......................done
Testing hour() + second() + millis() starting!......................done
Xor truly random starting!......................done
Xor cheat random starting!......................done
Ready! The results are :
Xor fast random : 2038 millis
Processing nextInt random : 3056 millis
Processing normal random : 3094 millis
Java normal random : 3556 millis
system.nanotime() : 1135 millis
hour() + second() + millis() : 17731 millis
Xor truly random : 3175 millis
Xor cheat random : 1954 millis