问题描述
我想生成银行帐号,该号码必须以32开头,例如32098723,32162545,32752934等。它必须是8位数。任何人都可以帮助我,谢谢你。
我尝试过:
public long GetNewAccountNumber(long accountNumber)
{
随机随机= new Random();
long newAccountNumber = random.Next( 32000000,33000000);
返回newAccountNumber;
}
I want to generate bank account number, the number must start with 32 like for example 32098723, 32162545, 32752934 etc.. and it has to be of be 8 digits. Can anyone help me please and thank you.
What I have tried:
public long GetNewAccountNumber(long accountNumber)
{
Random random = new Random();
long newAccountNumber = random.Next(32000000, 33000000);
return newAccountNumber;
}
推荐答案
String startWith = "32";
Random generator = new Random();
String r = generator.Next(0, 999999).ToString("D6");
String aAccounNumber = startWith + r;
string accNumber = String.Format("32{0}", r.ToString("D6"));
现在注意来自@ppolymorphe和@ George-Swan的评论 - 银行账户不仅仅是随机数,他们遵循非常具体的规则。一旦你产生了你的号码,你应该检查它是否有效。
这是George的链接的可点击版本 [ ]
这是验证工具的另一个例子 []
这是一篇关于主题的Codeproject文章 []
有许多商业产品和API可以进行验证。
Now note the comments from @ppolymorphe and @George-Swan - Bank Accounts are not just random numbers, they follow very specific rules. Once you have generated your number you should check that it is valid.
Here is a clickable version of George's link https://www.vocalink.com/media/1733/vocalink-validating-account-numbers-v350.pdf[^]
Here is another example of a validation tool Sortcode and Bank Account Validation - C# Developers Guide[^]
And here is a Codeproject article on the subject IBAN Validator[^]
There are many commerical products and APIs available to do the validation.
这篇关于如何在C#上生成随机银行帐号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!