Intermec PX4i Fingerprint Developer's Guide (old) - Page 61
Generating Random Numbers, Calling the RANDOM Function, Using a RANDOMIZE Statement
View all Intermec PX4i manuals
Add to My Manuals
Save this manual to your list of manuals |
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