2-191
2 Instruction Descriptions
NJ-series Instructions Reference Manual (W502)
Math Instructions
2
Rand
Rand
The Rand instruction generates pseudorandom numbers.
*1 If you omit the input parameter, the value will be 0. It will not be the value that is specified for the Initial Value attribute.
*2 0.00000000000000e+0 to 1.00000000000000e+0
The Rand instruction specifies random number Rnd. The value of Rnd is different each time the
instruction is executed: Random number pattern Seed specifies the random number system. If the
value of Seed is the same, the same random number series is generated each time the power sup-
ply is turned ON. This allows you to generate a repeatable series of random numbers.
If the value of Seed is 0, random numbers that cannot be repeated are generated. If you do not want
to generate the same series of random numbers each time the power supply is turned ON, set the
value of Seed to 0.
The following programming example is for when Seed is UINT#1.
Instruction Name FB/FUN Graphic expression ST expression
Rand Random Number FB Rand_instance(Execute,
Seed, Rnd);
Variables
Name Meaning I/O Description Valid range Unit Default
Seed Random num-
ber pattern
Input Random number pattern Depends on data type.
---
*1
Rnd Random num-
ber
Output Random number
*2
--- ---
Boolean
Bit strings Integers
Real
numbers
Times, durations,
dates, and text strings
BOOL
BYTE
WORD
DWORD
LWORD
USINT
UINT
UDINT
ULINT
SINT
INT
DINT
LINT
REAL
LREAL
TIME
DATE
TOD
DT
STRING
Seed OK
Rnd OK
Function
Rand
Rand_instance
Execute ENO
Seed Rnd
Rand_instance(A, UINT#1, abc);
LD ST
abc
UINT#1
A
Rand
Rand_instance
Execute ENO
Seed Rnd