随机帐号生成 [英] Random Account number geneartion

查看:98
本文介绍了随机帐号生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想为我的项目生成13位唯一的随机帐号,该帐号包括分支代码,区号,并且所有这些都应存储在sql 2008数据库中,并且此代码应在c#中,请为此提供帮助



在此先感谢


i want to generate 13 digits unique random account number for my project this number includes branch code, area code and all should be stored in database sql 2008 and code for this should be in c# please help me for this



thanks in advance

推荐答案

出了什么问题?我们无法为您提供代码,我们也不知道分支或区域代码格式,因此我们对其其余部分一无所知.但是随机很容易:

What is the problem? We can''t give you code, we don''t know the branch or area code formats, so we have no idea about the rest of it. But Random is easy:

private Random rand = new Random(); // Class level random number generator
...
int randomNumber = rand.Next(1000000);           // Generate a random number between 0 and 999999
string randomCode = randomNumber.ToString("D6"); // Convert it to six digits, 0 padded.

然后结合您的分支和区号,看看它是否已经在数据库中了!
您可能想添加一个校验位或类似的数字,以使人为错误更难以插入...

Then combine with your branch and area codes, and see if it is in the db already!
You might want to add a check digit or similar to make it harder for human error to slip in...


这篇关于随机帐号生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆