Click or drag to resize
RandomStringIdentifier Method (IRandom, Int32, Single)
Generates a random string using only decimal digits and letters from the English alphabet, both upper and lower case, plus the underscore character which can occur randomly with a specified probability, with the restriction that the first character cannot be a decimal digit.

Namespace: Experilous.MakeItRandom
Assembly: Assembly-CSharp-firstpass (in Assembly-CSharp-firstpass.dll) Version:
public static string Identifier(
	this IRandom random,
	int length,
	float underscoreProbability


Type: Experilous.MakeItRandomIRandom
The pseudo-random engine that will be used to generate bits from which the return value is derived.
Type: SystemInt32
The length of the string to be generated.
Type: SystemSingle
The probability of any specific index in the string being a underscore character. Must be in the range [0, 1].

Return Value

Type: String
A random string which conforms to typical rules of valid identifier names in many programming languages.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IRandom. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

It is guaranteed that except at the very beginning of the string, two underscore characters will never be generated one immediately after the other, regardless of the underscore probability.

An underscore probability of 0 will guarantee that there are no underscore at all, while a probability of 1 will guarantee that every second character is a underscore character. Probabilities less than 1 but greater that 0.5 will be biased toward the same every-other character outcome, but will have a chance of generating longer sequences of non-underscore characters, rather than being strictly limited to one non-underscore character at a time.

See Also