Is there a good guide somewhere for using pickrandom

I have problems with pickrandom. I try pickrandom directly on a drawbox command but drawbox can’t be applied to an array. I try drawbox on pickrandom but drawbox can only operate on a color (not another command). So I tried pickrandom on separate drawbox commands for each object but instead it creates a checkerboard…and the same order each time. What is wrong???
(This was in a for loop, it should’ve been able to produce, for example, red blue red blue blue red red blue or red blue red blue red blue red blue, etc., but I would’ve been getting blue red blue red blue red blue red every time code was run)

pickrandom is just a function in the app, you cannot use it outside of it, unless whereever you are using pickrandom has created this function(with the same purpose). Picking something randomly from a variable is actually more complex when writing the JavaScript code.

Refer to this reply Super-charge your coding skills! by Mr Ben.

1 Like

Hey there,

pickRandom() is a function we wrote for use within the app. If you give it an array, it will return a random item in that array. If you give it a number, it will return a random number between 0 and the number you entered in.

It sounds like you were using it like this?

pickRandom(drawBox(['red', 'blue', 'yellow']))

Try changing it to something like this:

drawBox(pickRandom(['red', 'blue', 'yellow']));

Hope this helps!
Ben

3 Likes