Tag Archives: random

Draw ransom note text in a RichTextBox in C#

This example is similar to the post Draw ransom note text in C# but it writes text into a RichTextBox instead of on a PictureBox. This has the following advantages. The code is simpler The RichTextBox can arrange text more … Continue reading

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

Draw ransom note text in C#

This example draws each of the characters in a string in a different random font to produce a ransom note text effect. The program starts by using the following code to create arrays holding font names and brushes from which … Continue reading

Posted in graphics, strings | Tagged , , , , , , , , , , , , | 1 Comment

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