c# - Uniqueness for a shortened guid -
i have append unique code querystring, every url generated. so, option chose shorten guid (found here on so).
public static string createguid() { guid guid = guid.newguid(); return convert.tobase64string(guid.tobytearray()); }
will unique guid, cause have several urls generate , guid saved in db.
you should watch out if using in url. while string shorter, potentially have characters illegal in urls, may need run past
httputility.urlencode()
to safe. of course, once that, little longer again.
edit:
your comment makes seem want sort of math, here goes:
let's assume have 24 alphanumeric characters time, , casing not matter. means each character can 0-9 + a-z or 36 possibilities. makes 24 ^ 36 different possible strings. refer website then:
http://davidjohnstone.net/pages/hash-collision-probability
which lets plug in possible values , number of times need run code. 24^36 equivalent 2^100 (i arrived @ number after googling, may incorrect). plugging in 100 "number of bits in hash" field @ link above means if run code 1000000 times, still have 3.944300×10^19 odds of collision, or same value coming twice. that's miniscule, may run issues if writing used many many more times that.
Comments
Post a Comment