Generate 8 digit uinque id in c#

2020-07-13 10:32发布

I need to generate 8 digit unique id in c#. On my site a user will register and I need to generate a unique id for him in c# code(I don't want this logic in DB), after inserting the id I need to save it in database.

Edit: I need that numbers to be generated in random manner everytime.

标签: c# asp.net
7条回答
狗以群分
2楼-- · 2020-07-13 11:20

Although not 8 digits, I'd use a GUID for that purpose:

var id = Guid.NewGuid().ToString()

From Wikipedia:

Ideally, a GUID will never be generated twice by any computer or group of computers in existence. The total number of unique keys (2^128 or 3.4×10^38 - in relation there are about 1.33×10^50 atoms on earth) is so large that the probability of the same number being generated twice is extremely small, and certain techniques have been developed to help ensure that numbers are not duplicated

查看更多
登录 后发表回答