Created
August 6, 2013 14:21
-
-
Save olih/6164911 to your computer and use it in GitHub Desktop.
Generate numeric ids
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
# | |
#Creator: 2013, Olivier Huin (https://github.com/olih) | |
#License: Eclipse Public License - v 1.0 | |
#Contributors: | |
# | |
#This code is a quick hack and should not be used for production | |
#as it is not optimized and the random numbers could be predicted. | |
generate8Digits = ()-> | |
num=Math.floor(Math.random()*90000000) + 10000000; | |
return num | |
generateNumericId= (size)-> | |
div=Math.ceil(size/8) | |
r = "" | |
for i in [0..div] | |
r=r+generate8Digits() | |
r=r.substring(0,size) | |
return r; | |
generateNumericIds= (howmany, prefix, size)-> | |
r=[] | |
for i in [0..howmany] | |
r.push prefix + generateNumericId(size) | |
return r | |
#Generate a list of ids with a prefix | |
console.log generateNumericIds(8,"entity/",12) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment