Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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!
Posted
Comments
I.explore.code 17-Aug-12 5:22am    
what have you tried yourself? this is not a place where people will do your work for you without you telling them what approaches have you already tried that hasn't worked.
marcelinha 13-May-15 14:52pm    
why don't u shut ur mouth and help the guy?

Something like this:

C#
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);



Read more about Random here:
http://msdn.microsoft.com/en-us/library/system.random.aspx
 
Share this answer
 
v2
Comments
I.explore.code 17-Aug-12 5:34am    
you guys are not exactly helping him. If he had even bothered to use his imagination and used Visual Studio Intellisense for the word "Random", he wouldn't be asking this question here.
marcelinha 13-May-15 14:54pm    
again, why don't u shut up... and go f*** urself
C#
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());



        }
 
Share this answer
 
v2
Comments
I.explore.code 17-Aug-12 5:34am    
you guys are not exactly helping him. If he had even bothered to use his imagination and used Visual Studio Intellisense for the word "Random", he wouldn't be asking this question here.
VB
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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900