rand

PLCopen motion icon

 Function Block - Returns a pseudo-random integer value between 0 (zero) and (base - 1).

Inputs

Input

Data Type

Range

Unit

Default

Description

base

DINT

1 to 2147483647

N/A

No default

The number of possible outcomes.

Example: When base is 5, there are 5 possible outcomes: 0,1,2,3,4.

Outputs

Output

Data Type

Range

Unit

Description

Return Value

DINT

0 (zero) to (base - 1)

N/A

The generated pseudo-random number.

Remarks

  • rand uses a fast high-quality number generation algorithm.
    • The algorithm is not cryptographically secure.
    • It is sufficient where security is not a concern.
  • There is no way to seed the random number generator.
    • On first use, the random number generated is seeded by time.
    • While unlikely, it is possible to receive the same pattern of generated numbers after the controller reboots.

FBD Language Example

Not available.

FFLD Language Example

Not available.

IL Language Example

Not available.

ST Language Example

dieValue := 1 + rand(6);