e1e1qg
Last Updated: February 25, 2016
·
1.462K
· iondrimba
178548

Generating Random Numbers and Strings in C#

//RANDOM STRING
string random = System.IO.Path.GetRandomFileName().Replace(".", string.Empty);

//RANDOM PASSWORD/STRING
string randomPass = System.Web.Security.Membership.GeneratePassword(10, 0);

//RANDOM INT
System.Random randomInt = new System.Random((int)System.DateTime.Now.Ticks);
int start = 1;
int size = 1000;
int result= randomInt.Next(start, size);

source: http://blog.codeeffects.com/Article/Generate-Random-Numbers-And-Strings-C-Sharp
Say Thanks
Respond

2 Responses
Add your response

8720
D3b2094f1b3386e660bb737e797f5dcc

All of the above are pseudo-random values, which is likely fine for most scenarios.

System.Security.Cryptography.RandomNumberGenerator is the base class for cryptographically secure random values that are not deterministic/predictable.

See the example @ http://msdn.microsoft.com/en-us/library/system.security.cryptography.rngcryptoserviceprovider.aspx

over 1 year ago ·
8734
178548

Thanks for pointing that out =]

over 1 year ago ·