Barebones function 230

From Unofficial QEdit Wiki Guide
Jump to: navigation, search

Barebones function 230

Function 230: 230:

  • Function 230 = Random number generator.

Random number generator

Random number generator generates a random number. To use the random number generator make a new function. Then leti register 121 to equal the maximum value that you want it to be (note maximum valid value is 10,000 in dec.) Then call function 230 and end with a ret. Your returned random number will be between 1 and the maximum value you stated in register 121, your random number will be stored in register 122.

Barebones function 230 = Function 230 is the random number generator. It is used to generate random numbers for as many different reasons as you can think of why you would need something to be random.

Use

Function 230 is the random number generator. It is used to generate random numbers for as many different reasons as you can think of why you would need something to be random.

How the function appears in the script


230:     leti R120, 00000000 //Makes register 120 equal 00000000.
         sync  //Waits 1 frame.
         gettime R123 //Stores the current number of frames in the day in register 123.
         clear R122 //Makes register 122 equal 00000000.
         get_random R120, R122 //Gets a random number between the value of register 120 , and the value of register 121. Then stores the returned random number in register 122.
         sub R123, R122 //Subtracts the value of register 122 from the value of register 123 and stores the result in register 123.
         let R122, R123 //Makes the value of register 122 equal the value of register 123.
         sub R121, R120 //Subtracts the value of register 120 from the value of register 121 and stores the result in register 121.
         div R123, R121 //Divides the value of register 123 by the value of register 121 and stores the result in register 123.
         mul R123, R121 //Multiplies the value of register 123 by the value of register 121 and stores the result in register 123.
         sub R122, R123 //Subtracts the value of register 123 from the value of register 122 and stores the result in register 122.
         add R122, R120 //Adds the value of register 120 to the value of register 122 and stores the result in register 122.
         addi R122, 00000001 //Adds 00000001 to the value of register 122.
         clear R120 //Makes register 120 equal 00000000.
         clear R121 //Makes register 121 equal 00000000.
         clear R123 //Makes register 123 equal 00000000.
         ret 

Also see

leti, sync, gettime, clear,

get_random, sub, let, div,

mul, add, addi, ret