Random Numbers in Dynamo
1-2 Generate Random Numbers in Dynamo – Practice Exercise
In this exercise, we will create a list of random numbers in Dynamo
Task 1: Open Revit and Dynamo
- Open Revit 2021 then open the “Random Numbers Dynamo_sample project_2021.rvt” sample file provided with this lesson.
- In the “Manage” ribbon, click the “Dynamo” button to launch Dynamo.
- Once Dynamo opens, click the “New” button to create a new script file
Task 2: Install the Clockwork package (if it is not installed already)
- Check your node library to see if the “Clockwork” package is installed.
- If you do not see it, click “Packages” in the menu bar then click “Search for a Package”.
- Type “Clockwork” in the search bar.
- Click the download arrow next to “Clockwork for Dynamo 2.x” in the results window to install the package.
Task 3: Define parameters for random number list
- You are going to generate a list of random numbers ranging from 1 to 5. To do this, double click an empty space in the Dynamo workspace to create a node block.
- In the Code Block, type the number 1 followed by a semicolon in the code block. Press the “Enter” key to create a new line.
- Type the number 5 followed by a semicolon. Press the “Enter” key to create a new line.
- Type the number 100 followed by a semicolon.
- Your code block should look like the following:
Task 3: Create the random number list
- In the node library, navigate to the “Clockwork” category.
- In “Clockwork”, click the “List” category then click the “RandomList” sub-category.
- Click the “AsIntegers” node to add it to your script.
- Connect the output from the number 1 in the Code Block to the “min” input of the RandomList.AsIntegers node.
- Connect the output from the number 5 in the Code Block to the “max” input of the RandomList.AsIntegers node.
- Connect the output from the number 100 in the Code Block to the “amount” input of the RandomList.AsIntegers node.
- These inputs will generate 100 random numbers ranging from 1 to 5.
Task 4: Add number slider
- You want to interactively generate the list of numbers so we’ll use a Number Slider to specify the “seed” input of the RandomList.AsIntegers node.
- Type “number slider” in the node library search bar. Click to add the Integer Slider to your script.
- Connect the output of the Number Slider to the “seed” input of the RandomList.AsIntegers node.
- Type “watch” in the node library search bar and click the add a Watch node to your script.
- Connect the output of the RandomList.AsIntegers node to the watch node.
- Adjust the slider on the Number Slider and observer the results in the Watch node.
- Your script should look like this:
Task 5: Group the Nodes
- Pick a spot in the upper left of the Dynamo workspace and click and hold the left mouse button.
- Drag the selection window to the lower right-hand corner to select all of the nodes.
- Right-click and click the “Create Group” option.
- Double click the group title and type “Generate Random Numbers”.
- Right-click the group and select a new color
- In the menu bar, click Save to save your Dynamo script file.