Tag Archives: random

Produce a repeatable series of “random” numbers in C#

The Random class can generate a series of pseudo-random numbers. They’re called “pseudo-random” rather than “random” because the numbers are generated by a mathematical algorithm rather than by some completely unpredictable process such as observing a source of radioactive decay … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , , , , | Leave a comment

Make extension methods to generate random double values in C#

This example adds extension methods to the Random class to generate double values within a specified range. The Random class provides methods for generating pseudo-random numbers. The Next method has three overloaded versions that produce a non-negative integer, an integer … Continue reading

Posted in extension methods, mathematics | Tagged , , , , , , , , , , | 1 Comment

Make a hangman game in C#

Special thanks to Jeff Scarterfield for the skeleton drawing used by the program. This example builds a simple hangman game that uses the dictionary created by the example Use LINQ to select words of certain lengths from a file in … Continue reading

Posted in algorithms, files, games, graphics, strings | Tagged , , , , , , , , , , , , | Leave a comment

Fill a shape with random lines in C#

Click and drag to draw a shape. When you release the mouse, the program closes the shape and fills it with random line segments. The following code shows how the program lets you draw a shape. // The points selected … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , , , , , , | Leave a comment

Fill an ellipse with random lines in C#

As the title implies, this example draws an ellipse filled with random lines. It cannot simply draw the ellipse in the form’s Paint event handler, however. That would make the program generate a new set of random lines every time … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , | Leave a comment

Generate random data in an Access database in C#

This example shows how you can generate random data for students and their test scores in an Access database. I often build examples that manipulate databases. Those examples are more interesting if the database holds lots of data, but it’s … Continue reading

Posted in ADO.NET, algorithms, database | Tagged , , , , , , , , , , , , , , | Leave a comment

Select random objects from an array in C#

This example builds a generic extension method that lets you easily select random objects from an array. The following code shows the extension method and the RandomTools class that defines it. public static class RandomTools { // The Random object … Continue reading

Posted in algorithms, arrays, mathematics, variables | Tagged , , , , , , , , , , , , | Leave a comment

Use VBA code to pick random cells from the currently selected cells in an Excel workbook

This example shows how you can use VBA code to pick random cells in an Excel workbook. Sooner or later, many programmers need to write code to control another application such as the Microsoft Office applications, either for their own … Continue reading

Posted in Excel, VBA | Tagged , , , , , , , , , , | Leave a comment

Make a password manager in C#

Before I discuss this example, let me make a disclaimer and say that I can’t guarantee this application’s performance. I think it is secure but for something as important as passwords you need to merely use this program as an … Continue reading

Posted in algorithms, cryptography, mathematics, registry, system | Tagged , , , , , , , , , , , , , , , , , , , | 2 Comments

Use cryptographic methods to generate random passwords in C#

Lately I’ve gotten more than a little tired of having to generate random passwords that obey all sorts of stupid rules for various web sites. Who cares if I use a strong password on a web site that just sends … Continue reading

Posted in algorithms, cryptography, mathematics, system | Tagged , , , , , , , , , , , , , , , , , , | 1 Comment