Random Hexadecimal Numbers using .NET

In this example, we will see how to generate random hexadecimal numbers using .NET. We will be using the Random class to do so.

Here’s how to generate 10 random hexadecimal numbers

static void Main(string[] args)
Random random = new Random();
int i = 0;
while (i < 10)

In the example shown above, the "X" format specifier in the ToString() statement converts an integer to the string representation of a hexadecimal value.


Hexadecimal C#

About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: