Creating a "random" number in a macro
-
I'm trying to make a macro for purging and cleaning the nozzle, with the purge bucket having two containers (one on each side of the brush).
And to keep only one of the purge buckets filling up i want to generate a variable to select what bucket to use randomly for each time.My goal is to "randomly" output "0" or "1", with 0/1 being the left/right bucket (0=left & 1=right). But i'm having problems creating the conditional GCode to output 0 or 1 at random.
Could someone please help me along?I'll post the macro once i've got the randomizing working here so those who feel like it can take a look and give feedback (it's based on a klipper macro).
EDIT: Using RRF 3.4.1 by the way!
-
@exerqtor said in Creating a "random" number in a macro:
I'm trying to make a macro for purging and cleaning the nozzle, with the purge bucket having two containers (one on each side of the brush).
And to keep only one of the purge buckets filling up i want to generate a variable to select what bucket to use randomly for each time.My plan goal is to "randomly" output "0" or "1", with 0/1 being the left/right bucket (0=left & 1=right). But i'm having problems creating the conditional GCode to output 0 or 1 at random.
Could someone please help me along?I'll post the macro once i've got the randomizing working here so those who feel like it can take a look and give feedback (it's based on a klipper script).
Well you don't say what firmware you are using but under 3.x there is a random function the will generate numbers.
Frederick
-
-
Yeah sorry i forgot to mention that, i'm on 3.4.1, and i've seen/found the function in the docs but i don't understand how to use / impliment it since i can't find any examples of it being used (not a programmer lol).
using this as an example for what i want
var bucket_pos = 0 set var.bucket_pos = {random function to output 0 or 1}
-
@exerqtor said in Creating a "random" number in a macro:
Yeah sorry i forgot to mention that, i'm on 3.4.1, and i've seen/found the function in the docs but i don't understand how to use / impliment it since i can't find any examples of it being used (not a programmer lol).
using this as an example for what i want
var bucket_pos = 0 set var.bucket_pos = {random function to output 0 or 1}
Hold on - let me see what the syntax is - only take a minute or two.
Frederick
-
@exerqtor said in Creating a "random" number in a macro:
Yeah sorry i forgot to mention that, i'm on 3.4.1, and i've seen/found the function in the docs but i don't understand how to use / impliment it since i can't find any examples of it being used (not a programmer lol).
using this as an example for what i want
var bucket_pos = 0 set var.bucket_pos = {random function to output 0 or 1}
set var.random_number = random(10) will set the variable to a pseudo-random integer number from 0 to 9.
So random(2) should return either 0 or 1.
Frederick
-
Ok so if i get it right, this:
var bucket_pos = 0 set var.bucket_pos = random(2)
Will end up making the "bucket_pos" variable either 0 or 1?
-
@exerqtor said in Creating a "random" number in a macro:
Ok so if i get it right, this:
var bucket_pos = 0 set var.bucket_pos = random(2)
Will end up making the "bucket_pos" variable either 0 or 1?
That syntax is correct and the docs say random returns a number from 0 to one less than the operand.
So if the docs are correct you will get a variable with 0 or 1.
Frederick
-
@fcwilt said in Creating a "random" number in a macro:
@exerqtor said in Creating a "random" number in a macro:
Ok so if i get it right, this:
var bucket_pos = 0 set var.bucket_pos = random(2)
Will end up making the "bucket_pos" variable either 0 or 1?
That syntax is correct and the docs say random returns a number from 0 to one less than the operand.
So if the docs are correct you will get a variable with 0 or 1.
Frederick
Well in that case i'll make a new thread for the macro in question and refer to this thread in a few. Thx!
-
-
-
-
-
-
-