Last active
January 21, 2022 10:59
-
-
Save tomchiverton/aed14c8df0ca87f196f30163c793a150 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
chars = "0123456789ACEFHJKLMNPRTVWXY"; // no B, only 8. No I only 1. etc | |
chars_length = chars.len() | |
// Based on https://cflib.org/udf/nBase36 | |
public string function int_to_id(numeric num){ | |
var stream = ''; | |
var res = ""; | |
var l = chars_length | |
if (num GT 0) { | |
while (num GT 0) { | |
res = num - l * int(num / l); | |
num = int(num / l); | |
stream = mid(chars,res + 1,1) & stream; | |
} | |
} else { | |
stream = num; | |
} | |
return stream; | |
} | |
public string function int_to_id_hash( numeric num,any seed=now().getTime() ){ | |
var t = ""&arguments.seed; // treat as string so can .right() | |
var raw = int_to_id( bitXor(t.right(5) ,arguments.num) ); | |
sleep(1); // to avoid any chance of consecutive calls getting same xor value | |
if( raw.len() gte 4 ){ // may or may not have any alpha chards | |
return ""&raw; | |
} | |
return ""&repeatString('0',4-raw.len())&raw; | |
} | |
writedump(int_to_id_hash( 345 )) | |
writedump(int_to_id_hash( 2345 )) | |
writedump(int_to_id_hash( 12345 )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment