Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

random character c#

//Random Uppercase letter:
Random rnd = new Random();            
int ascii_index = rnd.Next(65, 91); //ASCII character codes 65-90
char myRandomUpperCase = Convert.ToChar(ascii_index); //produces any char A-Z

//random lowercase letter:
Random rnd2 = new Random();            
int ascii_index2 = rnd2.Next(97, 123); //ASCII character codes 97-123
char myRandomLowerCase = Convert.ToChar(ascii_index2); //produces any char a-z

//Random letter irrespective of case: (search up "random number from 2 different ranges" for explanation)
int i = rnd.Next(1, 3) == 1 ? rnd.Next(65, 91) : rnd.Next(97, 123);
char anyLetter = Convert.ToChar(i);
Comment

PREVIOUS NEXT
Code Example
Csharp :: stop sound in unity 
Csharp :: c# image to byte array 
Csharp :: c# file exist 
Csharp :: play sound unity 
Csharp :: monogame fullscreen 
Csharp :: c# object initialization can be simplified 
Csharp :: remove element from sting array c# 
Csharp :: game object find 
Csharp :: use only one class from a namespace in c# 
Csharp :: elevated priviledge in c# 
Csharp :: get enum int by name 
Csharp :: c# start process and wait for exit code 
Csharp :: object to mouse unity 
Csharp :: rotation facing mouse unity 
Csharp :: c# + longest streak in strings 
Csharp :: How to read a XML on C# 
Csharp :: how to convert int to char in c# 
Csharp :: list of chars to string c# 
Csharp :: drag png to unity 3d 
Csharp :: c# encrypt decrypt string 
Csharp :: waitforseconds unity 
Csharp :: unity controls 3d 
Csharp :: c# how to terminate console application 
Csharp :: unity button press onclick click add C# 
Csharp :: asp.net get query string parameter 
Csharp :: regular expression for email in c# 
Csharp :: unity point between two positions 
Csharp :: convert ienumerable to list 
Csharp :: c# write variable in string 
Csharp :: jump in unity 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =