Generate Class
Definition
Provides a set of static methods for generating different types of values or sequences of values.
public static class Generate
- Inheritance
-
objectGenerate
Examples
The following example demonstrates how to use Generate to produce numeric ranges, random numbers, random strings, hash codes, and structured object portrayals.
using System;
using System.Collections.Generic;
namespace Cuemon;
public class GenerateExample
{
public void Demonstrate()
{
// Generate a range of values using a generator function
IEnumerable<int> numbers = Generate.RangeOf(5, i => i * 10);
Console.WriteLine(string.Join(", ", numbers)); // 0, 10, 20, 30, 40
// Generate a random integer in a specific range
int randomValue = Generate.RandomNumber(1, 101);
Console.WriteLine($"Random between 1 and 100: {randomValue}");
// Generate a random alphanumeric string
string randomStr = Generate.RandomString(12);
Console.WriteLine($"Random 12-char string: {randomStr}");
// Generate a random string from custom character buckets
string customRandom = Generate.RandomString(8, "ABCDEF", "123456");
Console.WriteLine($"Custom random string: {customRandom}");
// Generate a fixed string of repeated characters
string separator = Generate.FixedString('-', 20);
Console.WriteLine(separator); // --------------------
// Compute hash codes from convertible values
int hash32 = Generate.HashCode32(42, "hello", true);
long hash64 = Generate.HashCode64(42, "hello", true);
Console.WriteLine($"32-bit hash: {hash32}, 64-bit hash: {hash64}");
// Generate a structured portrayal of an object
var person = new { Name = "Alice", Age = 30 };
string portrayal = Generate.ObjectPortrayal(person);
Console.WriteLine(portrayal); // shows property names and values
}
}
Methods
| Name | Description |
|---|---|
| FixedString(char, int) | Generates a string from the specified Unicode character repeated until the specified length. |
| HashCode32(IEnumerable<IConvertible>) | Computes a suitable hash code from the specified sequence of |
| HashCode32(params IConvertible[]) | Computes a suitable hash code from the variable number of |
| HashCode64(IEnumerable<IConvertible>) | Computes a suitable hash code from the specified sequence of |
| HashCode64(params IConvertible[]) | Computes a suitable hash code from the variable number of |
| ObjectPortrayal(object, Action<ObjectPortrayalOptions>) | Generates a portrayal of the specified |
| RandomNumber(int) | Generates a random integer that is within a specified range. |
| RandomNumber(int, int) | Generates a random integer that is within a specified range. |
| RandomString(int) | Generates a random string with the specified length using values of LettersAndNumbers. |
| RandomString(int, params string[]) | Generates a random string with the specified length from the provided values. |
| RangeOf<T>(int, Func<int, T>) | Generates a sequence of |