Created
July 11, 2015 12:33
-
-
Save you21979/9f9fb02533b9248ff3ea to your computer and use it in GitHub Desktop.
ランダムなように見えるランダムを作るときに使う乱数
This file contains hidden or 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
var random = function(_seed){ | |
var seed = (_seed * 9301 + 49297) % 233280; | |
return [seed / 233280, seed]; | |
} | |
var createRandom = module.exports = function(_seed){ | |
var seed = _seed || +(new Date()); | |
return { | |
getSeed : function(){ return seed }, | |
getRandom : function(max, min){ | |
max = max || 1; | |
min = min || 0; | |
var w = random(seed); | |
var rnd = w[0]; | |
seed = w[1]; | |
return min + rnd * (max - min); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
通信せずに同期した乱数が欲しい時など