Intermec PM43/PM43c Fingerprint Developer's Guide (PC23d, PC43d/t, PM23c, PM43 - Page 55

Generating Random Numbers, Calling the RANDOM Function, Using a RANDOMIZE Statement

Page 55 highlights

Chapter 4 - Managing Input and Output Generating Random Numbers The Fingerprint commands RANDOM and RANDOMIZE are used to generate random numbers for test programs or other applications. Calling the RANDOM Function The RANDOM function generates a random integer within a specified interval. This example tests a random dot on the printhead of a 12 dots/mm printer: 10 MIN%=HEAD(-7)*85\100: MAX%=HEAD(-7)*115\100 20 DOTNO%=RANDOM(0,1279) 30 IF HEAD(DOTNO%)MAX% THEN 40 BEEP 50 PRINT "ERROR IN DOT "; DOTNO% 60 ELSE 70 BEEP 80 PRINT "HEADTEST: OK!" 90 END IF RUN Using a RANDOMIZE Statement To obtain a higher degree of randomization, the random number generator can be reseeded using the RANDOMIZE statement. You can either include an integer with which the generator will be reseeded, or a prompt will appear asking you to do so. This example prints a random pattern of dots after the random number generator has been reseeded: 10 RANDOMIZE 20 FOR Q%=1 TO 100 30 X%=RANDOM(50,400) 40 Y%=RANDOM(50,400) 50 PRPOS X%,Y% 60 PRLINE 5,5 70 NEXT 80 PRINTFEED RUN The printer returns: Random Number Seed (0 to 99999999) ? (prompt) For a higher degree of randomization, you can reseed the random integer generator with another random integer provided by a function such as TICKS: 10 A%=TICKS 20 RANDOMIZE A% 30 B%=RANDOM(1,100) 40 PRINT B% RUN The printer returns: 42 Fingerprint Developer's Guide 43

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163

Chapter 4 — Managing Input and Output
Fingerprint Developer’s Guide
43
Generating Random Numbers
The Fingerprint commands RANDOM and RANDOMIZE are used to generate
random numbers for test programs or other applications.
Calling the RANDOM Function
The RANDOM function generates a random integer within a specified interval.
This example tests a random dot on the printhead of a 12 dots/mm printer:
10
MIN%=HEAD(-7)*85\100: MAX%=HEAD(-7)*115\100
20
DOTNO%=RANDOM(0,1279)
30
IF HEAD(DOTNO%)<MIN% OR HEAD(DOTNO%)>MAX% THEN
40
BEEP
50
PRINT “ERROR IN DOT ”; DOTNO%
60
ELSE
70
BEEP
80
PRINT “HEADTEST: OK!”
90
END IF
RUN
Using a RANDOMIZE Statement
To obtain a higher degree of randomization, the random number generator can be
reseeded using the RANDOMIZE statement. You can either include an integer with
which the generator will be reseeded, or a prompt will appear asking you to do so.
This example prints a random pattern of dots after the random number generator
has been reseeded:
10
RANDOMIZE
20
FOR Q%=1 TO 100
30
X%=RANDOM(50,400)
40
Y%=RANDOM(50,400)
50
PRPOS X%,Y%
60
PRLINE 5,5
70
NEXT
80
PRINTFEED
RUN
The printer returns:
Random Number Seed (0 to 99999999) ?
(prompt)
For a higher degree of randomization, you can reseed the random integer generator
with another random integer provided by a function such as TICKS:
10
A%=TICKS
20
RANDOMIZE A%
30
B%=RANDOM(1,100)
40
PRINT B%
RUN
The printer returns:
42