// Random128 // // This script will create a VTS VM Command object and populate it with the code for // non-repeating pseudo-random number generator for range from 1 to 128 (MAX) // // INPUT: The script will require you to enter the max limit for the desired range. // // OUTPUT: GPRM0 will contain the generated number or "0" if end of sequence. // // USAGE: - end-link Random128 object to a condition splitter(s) testing GPRM0 and // link the splitter(s) to one or more case-lists with items to play (or directly to case-list if max No. 128) then goto 10 endif Remdr = MaxNum // Calculate number of Flag Registers required Nreg = 1 100 if (Remdr >= 16) then Remdr = Remdr - 16 Nreg = Nreg + 1 goto 100 endif if (Remdr == 0) then Remdr = 16 Nreg = Nreg - 1 endif // Calculate parameters for end-of-sequence detection LastNum = 1 EndFlags = 1 Flag[1] = 1 for i = 2 to Nreg Flag[i] = Flag[i-1] * 2 next i for i = 1 to Remdr LastNum = LastNum * 2 next i LastNum = LastNum - 1 for i = 1 to Nreg EndFlags = EndFlags * 2 next i EndFlags = EndFlags - 1 LastReg = Nreg // Calculate flow control depending on number of Flag Registers for i = 1 to Nreg if (i == LastReg) then Gotos[i] = 18 + (i - 1) * 4 + 3 + 1 else Gotos[i] = 18 + i * 4 + 1 endif next i Goto61 = 18 + (Nreg - 1) * 4 + 3 + 1 + Nreg + 3 + 1 Goto65 = Goto61 - 1 + 4 + 1 // // These prints are for debugging only // // print "MaxNum = ", MaxNum // print "Remdr = ", Remdr // print "Nreg = ", Nreg // print "LastReg = ", LastReg // for i = 1 to Nreg // print "Flag[", STR(i), "] = ", Flag[i] // next i // print "LastNum = ", LastNum // print "EndFlags = ", EndFlags // for i = 1 to Nreg // print "Gotos[", STR(i), "] = ", Gotos[i] // next i // print "Goto61 = ", Goto61 // print "Goto65 = ", Goto65 // Create the VM and sart commands generation Random128 = VMObjectAdd(0,"Random128") MenuAddPRECommand(Random128,"if (GPRM14 > 3854) GPRM14 &= 3854") MenuAddPRECommand(Random128,"GPRM14 *= 17") MenuAddPRECommand(Random128,"GPRM14 += 1") MenuAddPRECommand(Random128,"GPRM14 %= 128") MenuAddPRECommand(Random128,"GPRM0 = GPRM14") MenuAddPRECommand(Random128,"GPRM0 *= "+STR(MaxNum)) MenuAddPRECommand(Random128,"GPRM0 /= 128") MenuAddPRECommand(Random128,"GPRM0 += 1") MenuAddPRECommand(Random128,"GPRM12 = GPRM0") MenuAddPRECommand(Random128,"GPRM11 = GPRM0") MenuAddPRECommand(Random128,"GPRM11 %= 16") MenuAddPRECommand(Random128,"if (GPRM11 == 0) GPRM11 = 16") MenuAddPRECommand(Random128,"GPRM12 -= GPRM11") MenuAddPRECommand(Random128,"GPRM"+STR(LastReg)+" &= "+STR(LastNum)) MenuAddPRECommand(Random128,"GPRM0 = 1") MenuAddPRECommand(Random128,"if (GPRM11 > 1) GPRM0 *= 2") MenuAddPRECommand(Random128,"if (GPRM11 > 0) GPRM11 -= 1") MenuAddPRECommand(Random128,"if (GPRM11 > 0) Goto 16") // Generate Flag Register bit-setting for i = 1 to Nreg gosub 200 next i MenuAddPRECommand(Random128,"if (GPRM0 != 0) Goto "+STR(Goto61)) // Generate end-of-sequence detection for i = 1 to Nreg if (i == LastReg) then MenuAddPRECommand(Random128,"if (GPRM"+STR(i)+" == "+STR(LastNum)+") GPRM0 |= "+STR(Flag[i])) else MenuAddPRECommand(Random128,"if (GPRM"+STR(i)+" == 65535) GPRM0 |= "+STR(Flag[i])) endif next i MenuAddPRECommand(Random128,"if (GPRM0 != "+STR(EndFlags)+") Goto 1") MenuAddPRECommand(Random128,"GPRM0 = 0") // Generate output section MenuAddPRECommand(Random128,"Goto "+STR(Goto65)) MenuAddPRECommand(Random128,"GPRM0 = GPRM14") MenuAddPRECommand(Random128,"GPRM0 *= "+STR(MaxNum)) MenuAddPRECommand(Random128,"GPRM0 /= 128") MenuAddPRECommand(Random128,"GPRM0 += 1") if (Nreg > 1) then print msg "GPRM1 to GPRM",STR(LastReg)," will be used as the Flag Registers" else print msg "GPRM1 will be used as a Flag Register" endif end // Flag Register bit-setting subroutine 200 MenuAddPRECommand(Random128,"if (GPRM12 > "+STR((i-1)*16)+") Goto "+STR(Gotos[i])) MenuAddPRECommand(Random128,"if (GPRM0 & GPRM"+STR(i)+") GPRM0 = 0") MenuAddPRECommand(Random128,"if (GPRM0 != 0) GPRM"+STR(i)+" |= GPRM0") if (i <> LastReg) then MenuAddPRECommand(Random128,"GPRM12 = 128") endif return