Skip to content

Instantly share code, notes, and snippets.

@olih
Created August 6, 2013 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olih/6164911 to your computer and use it in GitHub Desktop.
Save olih/6164911 to your computer and use it in GitHub Desktop.
Generate numeric ids
#
#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