You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingDryFish.ILib.Random;// User provides their own arraystring[]names={"an","binh","chi"};int[]numbers={1,2,3,4,5};char[]letters={'A','B','C','D','E'};// Random from user's arraystringrandomName=ILibRandom.IRandomFromArray(names);// returns "binh"intrandomNumber=ILibRandom.IRandomFromArray(numbers);// returns 3charrandomLetter=ILibRandom.IRandomFromArray(letters);// returns 'D'// Random numbersintdice=ILibRandom.IRandomInt(1,6);// returns 4longbigNum=ILibRandom.IRandomLong(1000,9999);// returns 5432doublepercent=ILibRandom.IRandomDouble(0.0,1.0);// returns 0.73boolisHeads=ILibRandom.IRandomBool();// returns true// Random characterscharupper=ILibRandom.IRandomUppercase();// returns 'X'charlower=ILibRandom.IRandomLowercase();// returns 'm'charalphabet=ILibRandom.IRandomAlphabet('A','Z');// returns 'G'// Random colorsstringhexColor=ILibRandom.IRandomHexColor();// returns "#FF5733"stringconsoleColor=ILibRandom.IRandomConsoleColor();// returns "cyan"// Random GUIDstringguid=ILibRandom.IRandomGuid();// returns "a1b2c3d4-..."// Random from Listvarcities=newList<string>{"Hanoi","Saigon","Danang"};stringcity=ILibRandom.IRandomItem(cities);// returns "Saigon"
π API Reference
Array Methods
Method
Description
Example
IRandomFromArray(string[] array)
Random element from string array
ILibRandom.IRandomFromArray(names)
IRandomFromArray<T>(T[] array)
Random element from generic array
ILibRandom.IRandomFromArray(numbers)
Number Methods
Method
Description
Example
IRandomInt(int min, int max)
Random integer
ILibRandom.IRandomInt(1, 10)
IRandomInt()
Random integer (0-100)
ILibRandom.IRandomInt()
IRandomLong(long min, long max)
Random long
ILibRandom.IRandomLong(1000, 9999)
IRandomDouble(double min, double max)
Random double
ILibRandom.IRandomDouble(0.5, 1.5)
IRandomBool()
Random boolean
ILibRandom.IRandomBool()
Character Methods
Method
Description
Example
IRandomChar(char min, char max)
Random character
ILibRandom.IRandomChar('A', 'Z')
IRandomAlphabet(char min, char max)
Random letter only
ILibRandom.IRandomAlphabet('A', 'Z')
IRandomUppercase()
Random uppercase letter
ILibRandom.IRandomUppercase()
IRandomLowercase()
Random lowercase letter
ILibRandom.IRandomLowercase()
Collection Methods
Method
Description
Example
IRandomItem<T>(IList<T> list)
Random item from list
ILibRandom.IRandomItem(myList)
Color Methods
Method
Description
Example
IRandomHexColor()
Random hex color
ILibRandom.IRandomHexColor()
IRandomConsoleColor()
Random console color name
ILibRandom.IRandomConsoleColor()
Utility Methods
Method
Description
Example
IRandomGuid()
Random GUID string
ILibRandom.IRandomGuid()
π‘ Examples
Basic Usage
usingDryFish.ILib.Random;// User provides their own name arraystring[]names={"An","Binh","Chi","Dung"};stringwinner=ILibRandom.IRandomFromArray(names);Console.WriteLine($"Winner: {winner}");