Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

randomm number from 2 different ranges

/* Using Ternary Operator
	(condition) ? (if true, do this) : (otherwise, do this)
Have Initial Range from 1-2. Generate either 1 or 2. 
	If generates 1, then [true] range will be accepted (65-90 in this case)
	If generates 2, [false] range will be chosen (97-122 in this case) */
Random rnd = new Random();
int randomNum = rnd.Next(1, 3) == 1 ? rnd.Next(65, 91) : rnd.Next(97,123);

/* This method might not produce perfect probability distribution for all 
values if range sizes are not equal. The individual terms belonging to the 
larger range size will appear fewer times vs the individual terms in the 
smaller range */
Comment

PREVIOUS NEXT
Code Example
Csharp :: Open another form with C# Winforms 
Csharp :: copy 2d arrays C# 
Csharp :: rotating an object in unity 
Csharp :: two variable in one loop in one line c# 
Csharp :: c# get command line arguments 
Csharp :: c# shuffle 
Csharp :: how to get the hour on c# 
Csharp :: how to set rigidbody velocity in unity 
Csharp :: how to write int array to console c# 
Csharp :: c# combobox selected item 
Csharp :: how delete multiple row from relation in laravel 
Csharp :: unity random number 
Csharp :: get last element in a list vb.net 
Csharp :: c# static meaning 
Csharp :: c list add element 
Csharp :: c# underscore variable 
Csharp :: arrays in c# 
Csharp :: char contains c# 
Csharp :: c# calculator 
Csharp :: joystock movement 
Csharp :: c# get list of all class fields 
Csharp :: c# how to fill a datatable 
Csharp :: git find commits by file path 
Csharp :: unity color by rgb 
Csharp :: get tree node godot 
Csharp :: length of array c# unity 
Csharp :: raycasthit unity 
Csharp :: asp.net textarea disable resize 
Csharp :: asp.net model 
Csharp :: sqldatareader in c# 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =