Intermec PD42 Fingerprint Developer's Guide (old) - Page 61

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

Page 61 highlights

Chapter 4 - Managing Input and Output • STRING$ returns a specified number of a single character specified by its ASCII value. • VAL$ returns the numeric representation of a string expression. This is typically used with random files, which only accept strings. Note: Commands ending in $ typically return a string. For more information, see the Fingerprint Command Reference Manual. 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: Intermec Fingerprint Developer's Guide 45

  • 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
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187

Chapter 4 — Managing Input and Output
Intermec Fingerprint Developer’s Guide
45
STRING$ returns a specified number of a single character specified by its ASCII
value.
VAL$ returns the numeric representation of a string expression. This is typically
used with random files, which only accept strings.
For more information, see the
Fingerprint Command Reference Manual.
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:
Note:
Commands ending in $ typically return a string.