I have a code for string combinations via loop code.
I made a code to create a four-digit random string. And I want to create a license key by repeating my code 8 times.
e.g. D1c4-SXsc-DJod-10cK-Cm3q-m4N8-10x1-3cCd)
My code able to accurately create random strings. but, when the code call from the loop code, result of the code repeat the same string.
e.g. D1c4-D1c4-D1c4-D1c4-D1c4-D1c4-D1c4-D1c4
However, if I add a code to check the string through the message box, the exact result will be displayed.
This is my code :
private string Get_Product_Key() { string product_key = ""; for (int index = 0; index <= 7; index++) { var key = Get_Random_String(4); product_key = product_key + key + '-'; //MessageBox.Show(key); } return product_key; } private string Get_Random_String(int length) { Random random = new Random(); string input = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; var chars = Enumerable.Range(0, length).Select(x => input[random.Next(0, input.Length)]); return new string(chars.ToArray()); }
Please give me some advice.
https://stackoverflow.com/questions/66947756/problem-of-string-combinations-via-loop-code April 05, 2021 at 10:58AM
没有评论:
发表评论