L1VM - nanoid
L1VM - nanoid
I did write a nanoid unique ID generator module. I did use: nano ID in C.
Here is a small example:
// nanoid.l1com
//
// nanoid create unique ids demo
//
#include <intr.l1h>
(main func)
(set int64 1 zero 0)
(set int64 1 mod_nanoid 0)
(set string 65 idstr)
(set string s custom_alphabetstr "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-*#.:@")
(set int64 1 custom_len 64)
// init nanoid module
(mod_nanoid :nanoid_init !)
// create 21 char ID
(idstr :nanoid_create !)
(idstr :print_s !)
(:print_n !)
// set custom ID
(idstr custom_alphabetstr custom_len :nanoid_create_custom !)
(idstr :print_s !)
(:print_n !)
(zero :exit !)
(funcend)
#include <nanoid.l1h>
As you can see it is simple to use. You just have to use a target string which is big enough for the ID.
On Linux and Unix BSDs the /dev/urandom
random number generator is used. I did add a preprocessor flag to use the normal C random number generator on Windows.
Here is an example output:
$ l1vm lib/nanoid -q
iG25B3w52BxfBsOIUkDym
m68+euDfr9LCpsk2y43dy:HEJNdkDX3mkrg2ig7z::1nqIMlvy2q-7UaavkaPKnZ
Have fun!