emi_sastra
asked on
Random number
Hi All,
I want to create random number for transaction.
The random number is not just from 1 - 10, when we have 10 transaction then we have 1 to 10.
I mean the number created not a serial number.
And the random number created using keys provided by us.
Some kind of systematic readable encryption.
How could I do it ?
Thank you.
I want to create random number for transaction.
The random number is not just from 1 - 10, when we have 10 transaction then we have 1 to 10.
I mean the number created not a serial number.
And the random number created using keys provided by us.
Some kind of systematic readable encryption.
How could I do it ?
Thank you.
ASKER
Hi angus_young_acdc,
Your code seems not solve my question.
Your code will create a serial number at the end.
numberOne = 1
numberTwo = 10
At the end we will have a serial number from 1 to 10.
The random number is not just from 1 - 10, when we have 10 transaction then we have 1 to 10.
I mean the number created not a serial number.
Thank you.
Your code seems not solve my question.
Your code will create a serial number at the end.
numberOne = 1
numberTwo = 10
At the end we will have a serial number from 1 to 10.
The random number is not just from 1 - 10, when we have 10 transaction then we have 1 to 10.
I mean the number created not a serial number.
Thank you.
Struggling to understand. If you create random numbers between 1 and 10, you will not get serial numbers. You may get 3, 1, 6, 9, ... etc. If you wish, you can create random numbers between 1 and 100 or 1 and 1000.
ASKER
Hi CodeCruiser,
What I want is to create a number, not just a random number, what I mean random number is a number that is not easy to read, thus not easy to duplicate, for example, voucher.
In the past I've heard about a number that has checked digit. If the number after reversed has not the same checked digit, then the number is invalid number.
Thank you.
What I want is to create a number, not just a random number, what I mean random number is a number that is not easy to read, thus not easy to duplicate, for example, voucher.
In the past I've heard about a number that has checked digit. If the number after reversed has not the same checked digit, then the number is invalid number.
Thank you.
ASKER
I've just check these links :
http://www.ehow.com/how_5328637_calculate-check-digit.html
http://www.wikihow.com/Calculate-the-Check-Digit-of-a-Routing-Number-from-an-Illegible-Check
What do you think about it ?
Thank you.
http://www.ehow.com/how_5328637_calculate-check-digit.html
http://www.wikihow.com/Calculate-the-Check-Digit-of-a-Routing-Number-from-an-Illegible-Check
What do you think about it ?
Thank you.
Looks good.
ASKER
I am sorry, just back.
I try to convert it to VB, but failed.
private string GetUniqueKey()
{
int maxSize = 8 ;
int minSize = 5 ;
char[] chars = new char[62];
string a;
a = "abcdefghijklmnopqrstuvwxy zABCDEFGHI JKLMNOPQRS TUVWXYZ123 4567890";
chars = a.ToCharArray();
int size = maxSize ;
byte[] data = new byte[1];
RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider() ;
crypto.GetNonZeroBytes(dat a) ;
size = maxSize ;
data = new byte[size];
crypto.GetNonZeroBytes(dat a);
StringBuilder result = new StringBuilder(size) ;
foreach(byte b in data )
{ result.Append(chars[__b % (chars.Length - )>); }
<span class="code-keyword">retur n result.ToString();
}
What should I do ?
Thank you.
I try to convert it to VB, but failed.
private string GetUniqueKey()
{
int maxSize = 8 ;
int minSize = 5 ;
char[] chars = new char[62];
string a;
a = "abcdefghijklmnopqrstuvwxy
chars = a.ToCharArray();
int size = maxSize ;
byte[] data = new byte[1];
RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider()
crypto.GetNonZeroBytes(dat
size = maxSize ;
data = new byte[size];
crypto.GetNonZeroBytes(dat
StringBuilder result = new StringBuilder(size) ;
foreach(byte b in data )
{ result.Append(chars[__b % (chars.Length - )>); }
<span class="code-keyword">retur
}
What should I do ?
Thank you.
Where did you get that code? Following does not look right
<span class="code-keyword">retur n result.ToString();
<span class="code-keyword">retur
ASKER
- Where did you get that code? Where did you get that code?
From the link you provided.
https://www.experts-exchange.com/questions/28166529/Random-number.html?anchorAnswerId=39278214#a39278214
http://www.codeproject.com/Articles/14403/Generating-Unique-Keys-in-Net
Thank you.
From the link you provided.
https://www.experts-exchange.com/questions/28166529/Random-number.html?anchorAnswerId=39278214#a39278214
http://www.codeproject.com/Articles/14403/Generating-Unique-Keys-in-Net
Thank you.
That code contains html tags for some reason. Here is the converted code
private Function GetUniqueKey() As String
Dim maxSize As Integer = 8
Dim minSize As Integer= 5;
Dim chars As new char(62)
Dim a As string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
chars = a.ToCharArray()
Dim size As Integer = maxSize
Dim data As new byte(1)
Dim crypto As new RNGCryptoServiceProvider()
crypto.GetNonZeroBytes(data)
size = maxSize
data = new byte(size)
crypto.GetNonZeroBytes(data);
Dim result As new StringBuilder(size)
foreach b As byte in data
result.Append(chars(b % (chars.Length - 1))
Next
return result.ToString()
End Function
ASKER
Hi CodeCruiser,
I've compiled error :
Error 8 Character is not valid.
Error 7 Expression is of type 'Byte', which is not a collection type.
Error 3 Type 'Byte' has no constructors.
Error 5 Type 'Byte' has no constructors.
Error 1 Type 'Char' has no constructors.
Error 4 Type 'RNGCryptoServiceProvider' is not defined.
Error 6 Type 'StringBuilder' is not defined.
Error 2 Value of type '1-dimensional array of Char' cannot be converted to 'Char'.
Thank you.
I've compiled error :
Error 8 Character is not valid.
Error 7 Expression is of type 'Byte', which is not a collection type.
Error 3 Type 'Byte' has no constructors.
Error 5 Type 'Byte' has no constructors.
Error 1 Type 'Char' has no constructors.
Error 4 Type 'RNGCryptoServiceProvider'
Error 6 Type 'StringBuilder' is not defined.
Error 2 Value of type '1-dimensional array of Char' cannot be converted to 'Char'.
Thank you.
Another try
Private Function RNGCharacterMask() As String
Dim maxSize As Integer = 8
Dim minSize As Integer = 5
Dim chars As Char() = New Char(61) {}
Dim a As String
a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
chars = a.ToCharArray()
Dim size As Integer = maxSize
Dim data As Byte() = New Byte(0) {}
Dim crypto As New RNGCryptoServiceProvider()
crypto.GetNonZeroBytes(data)
size = maxSize
data = New Byte(size - 1) {}
crypto.GetNonZeroBytes(data)
Dim result As New StringBuilder(size)
For Each b As Byte In data
result.Append(chars(b Mod (chars.Length - 1)))
Next
Return result.ToString()
End Function
ASKER
What is RNGCryptoServiceProvider ?
Error 1 Type 'RNGCryptoServiceProvider' is not defined.
Thank you.
Error 1 Type 'RNGCryptoServiceProvider'
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great.
Thank you very much for your help.
Thank you very much for your help.
Open in new window