File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,11 +25,32 @@ def digit(raw):
2525
2626def codeGen (n ):
2727 codes_pool = []
28- for i in range (n - 1 ):
28+ for i in range (n ):
2929 code = ""
3030 for i in range (10 ):
3131 code += digit (codeSeedA )
3232 codes_pool .append (code )
3333 return codes_pool
3434
35- codes = codeGen (200 )
35+ '''
36+ Standard uuid
37+ '''
38+ import uuid
39+ def uuidGen (n ):
40+ codes_pool = []
41+ for i in range (n ):
42+ codes_pool .append (uuid .uuid4 ())
43+ return codes_pool
44+
45+ #codes_udf = codeGen(10000)
46+ codes_uuid = uuidGen (10000 )
47+
48+
49+ '''
50+ In the case of 200 activation code, it is almost equally fast.
51+
52+ As the size of code pool grows (e.g. to 10000), uuidGen() is twice slower than codeGen(),
53+ since uuid is checking whether duplications. Plus, the confidence level of codeGen() to not
54+ produce duplication lowers down as pool size increases.
55+
56+ '''
Original file line number Diff line number Diff line change 11#!/usr/bin/env
2- '''
3- Self-defined activation code
4-
5- 1. has length of 10
6- 2. mixture of letters and numbers
7- 3. unique throughtout 200 combos
8-
9- Pros:
10- total of 3656158440062976 combos, randomly generation of 200 is almost
11- guaranteed to be unique; Confident level if high without look up opeations.
12- And without look up, it's super fast :) The more codes needed, the effect
13- is more obvious.
14-
15- Cons:
16- Without back tracking, small chance would occur of duplication.
17- '''
182import random
193
204codeSeedA = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
21-
225def digit (raw ):
236 l = len (raw )
247 return raw [random .randrange (l )]
@@ -31,5 +14,3 @@ def codeGen(n):
3114 code += digit (codeSeedA )
3215 codes_pool .append (code )
3316 return codes_pool
34-
35- codes = codeGen (200 )
You can’t perform that action at this time.
0 commit comments