Xah Talk Show 2025-05-05 Ep652 Design of Id System of Random Sequence of Character


xah talk show 2025-05-05 chinese caligraphy cursive
xah talk show 2025-05-05 chinese caligraphy cursive

continue from Xah Talk Show 2025-05-03 Ep651 emacs lisp, add id to div tag, part 1

design of id system of random sequence of character

(* one second per post, for a year *)
365 24 60 60
(* 31536000 *)
HHHH------------------------------
random string

h5zsb
mT5cc
mpj7k
crnRx

jRg7c

sXCGxGHX4W
dQGT5
rBnFV
VsXJJ8bvdMtD3k5xgG28

HHHH------------------------------
random decimal

168
376
679
338
978628410
87655432934079046085

HHHH------------------------------

random hexadecimal
241c
1937
e70d
b2fd
eaca
5bf8d70fd9327bb19fe5

HHHH------------------------------

uuid
91165613-62c0-414e-8ded-7bd7c9511e1d
7e1f4551-90f1-47c9-970c-495ba2f45dca
4619ff1f-0613-4cb8-91a6-b20ddfb7fa42

fantastic new id design, using chinese chars

import math

# chinese chars in unicode cjk block range
chinese_char_count = 40959 - 19968 + 1
print("chinese_char_count")
print(chinese_char_count)
# 20992

chinese_id_length = 9

chinese_id_space_size = chinese_char_count**chinese_id_length

print("chinese id space size")
print(chinese_id_space_size)
# 4075356853195798845951

uuidTotal = 16**32
print("uuidTotal")
print(uuidTotal)

# need this many chinese chars to be equal power as uuid
print( math.log(uuidTotal, chinese_char_count ))
# 8.9151688225701
(defun xah-insert-random-chinese-char ()
  "insert random chinese char, 5 of them.
Created: 2025-05-05
Version: 2025-05-05"
  (interactive)
  (let (cstart cend)
    ;; range of chinese chars in unicode
    ;; #x4E00
    ;; 19968
    (setq cstart 19968)
    ;; #x9FFF
    (setq cend 40959)
    (dotimes (_ 5)
      (insert (format "%c" (+ cstart (random (- cend cstart))))))))

;; sample output
;; 纣躆動褤藓
;; 醣齻樈驵勔
;; 鼐桊婙听胳
;; 傲臞輡鿔褙

Xah Talk Show, emacs lisp, add id to div tag