本文介绍了如何生成6位数的随机优惠券号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友们..我想生成字母数字6位数的优惠券号码。
你能解决我的问题..
请一步一步明确指出我..
我在等你的答案..
谢谢!
My dear friends ..I want to generate Alphanumeric 6 digit coupon number.
Can you solve my problem..
Please specify me clearly step by step..
I am waiting your answers..
Thanks!
推荐答案
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var stringChars = new char[6];
var random = new Random();
for (int i = 0; i < stringChars.Length; i++)
{
stringChars[i] = chars[random.Next(chars.Length)];
}
var finalString = new String(stringChars);
了解更多关于此处的随机数:
static void Main(string[] args)
{
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random = new Random();
string result = new string(
Enumerable.Repeat(chars, 8)
.Select(s => s[random.Next(s.Length)])
.ToArray());
}
Function Password_GenPass( nNoChars, sValidChars )
' nNoChars = length of generated password
' sValidChars = valid characters. If zerolength-string
' ( "" ) then
' default is used: A-Z AND a-z AND 0-9
Const szDefault = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789"
Dim nCount
Dim sRet
Dim nNumber
Dim nLength
Randomize 'init random
If sValidChars = "" Then
sValidChars = szDefault
End If
nLength = Len( sValidChars )
For nCount = 1 To nNoChars
nNumber = Int((nLength * Rnd) + 1)
sRet = sRet & Mid( sValidChars, nNumber, 1 )
Next
Password_GenPass = sRet
Password_GenPass( 6, "" ) = & pwd &
End Function
这篇关于如何生成6位数的随机优惠券号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!