Skip to main content

RandomUtils


Namespace: FivePD.API.Utils#
File: Source/Utils/RandomUtils.cs#
Made by: HB-2012#

A collection of utilities that make it easier to select or generate random values.


Fields#

Random#

This is reasonably slower than using new Random(), but since all callouts get loaded at the same time, we shouldn't use the same seed (by default the system time is used, leading to very bad randomization). Unfortunately, this isn't thread-safe, but that shouldn't be a problem with FivePD.

Random instance that you can use to get random values in your callouts. This random should generate better random numbers than when you create your own randoms in code. Also have a look at the GetRandomNumber method.

Properties#

PedHases#

A list of all entries in the PedHash enum, minus the ones that break FivePD.

WeaponHashes#

A list of all entries in the WeaponHash enum.

VehicleHases#

A list of all entries in the VehicleHash enum.

Methods#

GetRandomNumber#

Selects a random number in the specified range. start is inclusive, end exclusive (so the number that is passed for start can also be returned, but end cannot).

Returns a number between start and end (could be equal to start).

Returns: int

Params:

  • start
    • Type: int
    • The inclusive minimum value
  • end
    • Type: int
    • The exclusive maximum value

Example#

To generate an inclusive number between 1 and 100, you would use the following code:

var myRandomNumber = GetRandomNumber(1, 101);

GetRandomPed#

Returns a random PedHash.

By default, this method will already exclude all skins that are incompatible with FivePD.

Returns: PedHash

Params: -

GetRandomWeapon#

Returns a random WeaponHash.

Entries in the exclusion list will be ignored.

Returns: WeaponHash

Params:

  • exclusions
    • Type: IEnumerable<WeaponHash>
    • A list of WeaponHash to ignore

GetRandomVehicle#

Returns a random VehicleHash.

Returns: Vehicle

Params: -

GetRandomVehicle#

Returns a random VehicleHash.

Entries in the exclusion list will be ignored.

Returns: VehicleHash

Params:

  • exclusions
    • Type: IEnumerable<VehicleHash>
    • A list of VehicleHash to ignore

GetRandomVehicle#

Returns a random VehicleHash from the given vehicle class.

Returns: VehicleHash

Params:

  • vehicleClass
    • Type: VehicleClass
    • The class of vehicles you wish to select a random hash from

GetRandomVehicle#

Returns a random VehicleHash from the given vehicle classes.

Returns: VehicleHash

Params:

  • vehicleClass
    • Type: params VehicleClass[]
    • The classes of vehicles you wish to select a random hash from

GetRandomVehicle#

Returns a random VehicleHash from the given vehicle classes.

Returns: VehicleHash

Params:

  • vehicleClass
    • Type: IEnumerable<VehicleClass>
    • The classes of vehicles you wish to select a random hash from

GetVehicleHashesForClass#

Retrieves all of the VehicleHashes from a given VehicleClass.

Returns: IEnumerable<VehicleHash>

Params:

  • vehicleClass
    • Type: VehicleClass
    • The classes of vehicles