Created
March 19, 2018 05:34
-
-
Save likai24/57c4c5758961abe0d843b0ea43db1c69 to your computer and use it in GitHub Desktop.
Random Collision Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
var count = 0; | |
var total = 0; | |
function getDt(){ | |
var dt = (new Date()).toString() | |
var p = /\d+:\d+:\d+/.exec(dt); | |
if(p.length > 0){ | |
return dt = p[0]; | |
} | |
} | |
function cryptoR(){ | |
let num = crypto.randomBytes(1, function(err, buffer) { | |
var num = buffer.toString('hex'); | |
num = parseInt(num, 16); | |
let dt = getDt(); | |
if(num > 240){ | |
total += 1; | |
console.log(`"${dt}", num: "${num}" try: "${count}" total:"${total}"\n`); | |
count = 0; | |
}else{ | |
console.log('\n'); | |
count += 1; | |
} | |
}); | |
} | |
function random(){ | |
let num = Math.random(); | |
let dt = getDt(); | |
if(num > 0.95){ | |
total += 1; | |
console.log(`"${dt}", num: "${parseInt(num*100)/100}" try: "${count}" total:"${total}"\n`); | |
count = 0; | |
}else{ | |
console.log('\n'); | |
count += 1; | |
} | |
} | |
setInterval(cryptoR, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment