Hey there, pickRandom() is a Grasshopper function.
JavaScript has a built-in function called Math.random() that returns a random number between 0 and 1 (for example, 0.61). You can use this with other Math functions to create something like pickRandom(), like this:
function pickRandom(argument) {
if (typeof argument === 'number') {
return Math.floor(Math.random() * Math.floor(argument)) + 1;
}
if (Array.isArray(argument)) {
return argument[Math.floor(Math.random() * argument.length)];
}
}
The JavaScript documentation at MDN has some great information on what you can use and how to use it. Take a look at “Built-in Objects” on the sidebar on the left.
As usual, let me know if you have any questions!
Ben
Hi, I’m Alexander .
I just completed grasshopper app and I want to learn more about JavaScript. Also, are those certificates I received valid for anything.
Wow! What an interesting and exciting journey into coding. The outlay of the Grasshopper program is superb. Introduction 1 & 2, thrusts somebody into coding. Was anticipating harder topics, but Array methods and Animation 1 & 2 were so cool, like sliding down a mountain top. Kudos to the Grasshopper team, you have really ‘lux fiat’ (show the light) in dark world of coding. You are ‘primus enterpere’ (best among equals) Will keep the coding vision alife. Thanks a lot.
I have learnt i lot of thing and i am currently making a small car racing game but i am not able to detect obstacle please tell how can i write a code that can do something when an object touches other please tell?
@fallenangel74 The Coding that doctor’s offices use are placing procedures with a code for insurance identification, data entry. Where this is wiring the program that you would use to enter the data.