Table of Contents

Class RandomHelper

Namespace
VisioForge.Core.Helpers
Assembly
VisioForge.Core.dll

Provides utility methods for generating random values and unique identifiers.

public static class RandomHelper

Inheritance

Inherited Members

Remarks

This class offers thread-safe methods for generating random integers and timestamp-based unique identifiers useful for file naming, logging, or tracking purposes.

Methods

Get()

Generates a non-negative random integer.

public static int Get()

Returns

int

A 32-bit signed integer greater than or equal to 0 and less than MaxValue.

Remarks

This method uses the shared Random instance to generate values. For thread-safe operations in multi-threaded scenarios, consider implementing additional synchronization if needed.

GetWithDate()

Generates a unique string identifier combining the current timestamp with a random number.

public static string GetWithDate()

Returns

string

A string in the format "YYYY_M_D_H_m_s_ms_randomNumber" where each component represents the current date/time values and a random integer. For example: "2022_2_4_14_30_45_123_456789".

Remarks

This method is useful for generating unique file names, log entries, or any identifier that requires both temporal ordering and uniqueness. The timestamp ensures chronological sorting while the random number helps prevent collisions when called multiple times within the same millisecond.