Last active
October 20, 2016 02:20
-
-
Save marsen/9883538 to your computer and use it in GitHub Desktop.
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
//隨機GUID | |
function RandomGUID(){ | |
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); | |
return v.toString(16); | |
}); | |
} | |
//隨機整數 | |
function RandomNum(Min,Max){ | |
if(Max > Min){ | |
//return Math.floor(Math.random() * (Max - Min + 1)) + Min; | |
return ~~((Max-Min) * Math.random())+Min; | |
}else{ | |
console.log("function RandomNum exception"); | |
} | |
} | |
//隨機日期 random date | |
function getRandomDate(from, to) { | |
if (!from) { | |
from = new Date(1900, 0, 1).getTime(); | |
} else { | |
from = from.getTime(); | |
} | |
if (!to) { | |
to = new Date(2100, 0, 1).getTime(); | |
} else { | |
to = to.getTime(); | |
} | |
return new Date(from + Math.random() * (to - from)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment