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
Written by Ion D. Filho
Related protips
2 Responses
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
·
Thanks for pointing that out =]
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Csharp
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#