# Creating Fractal Flame scripts Pt 3

Hi!

Well, hopefully you managed to follow the previous tutorials on page 1 and 2. If you haven’t you really need to go back and follow those through, this one is more advanced and won’t make a lot of sense if you haven’t completed the first two lessons.

This next tutorial will focus on an absolute central part of making scripts, and that is to introduce an easy way to randomise values within the script. So you might want to randomise the screen rotation, or the value of a variation, or any other number value. To do this, we’re going to add a few lines of code to our script which will give us both random whole numbers, and random non whole, 2.3 for example.

Time Needed : 20 minutes

How to add a random number function for our JWildfire fractal scripts. Thanks to Jesus Sosa and Rick Sidwell for the code to do this.

1. # Open your script file in your text editor

We need to do this so we can paste our new function into it. In the screenshot you’ll see where the code is to be pasted. Underneath all those import.org commands. Hit return a few times to make a space there.

2. # For this next part you’ll need to copy the following code into your clipboard.

Visit this link for the code Copy the code or click the copy to clipboard button…

3. # Switch back to your script and paste

Go back to your script where you made the blank lines, and shown in step 1, click to the left side in the blank area, then right click and choose paste.

4. # You should see your pasted code

As in the screenshot below, once you’ve selected paste then that will be inserted into your script. Don’t worry at all about not understanding what it does. I’m about to explain.

5. # Understanding how to apply the random function to things.

Now what we do, is we look for something we can test this on. I’m going for screen rotation, which usually has a number between 1 and 360 for the degrees of rotation. As you can see numbers are in brackets, but we’re going to plug in our new “range” command.

6. # Adding the range command

The syntax of the range is as follows..
range(value1 , value 2)
These values for now are whole numbers. So, between the brackets where the 0 was for camera roll, we’re going to add range(1,360) . It will look confusing as there will now be two lots of brackets. If ever you get errors make sure you have the same amount of brackets on the left as on the right.

7. # Running the modified script

So, now you have added the range, go ahead and save the script file, then we want to be back into JWildfire. You’ll need to hit the Scan button to get JWildfire to re-read the scripts to pick up your modified version.

8. # Result ! our rotation is now randomised.

Now highlight your script, and click the Run button, if all has gone well, you’ll see that your rotation of the flame has now been randomised! Each time you run the script it will randomise the rotation. If you got an error, please go back and make sure what you’ve entered is the same as what’s on these shots, brackets etc. Sometimes the semi-colon that ends all lines gets deleted accidentally,make sure that is still there. Congratulations you’ve just learned a hard part of scripting.

9. # Try other values to have a play

The tricky part is knowing which values to plug into the range command, here’s a good tip. Go to your JWildfire and adjust the values manually to see what kind of values you want to put into the range command. Make a note of the lowest and highest. Pitch between 10 and 50 say, and add a range(10,50) to the pitch in the script. It’s worth noting that you can use negative numbers, as well as decimal values. BUT if you use decimal values make sure both numbers are decimal range(0.5 , 2.5) etc or you’ll get an error.

##### Tools
• Text editor like Notepad ++
##### Materials
• JWildfire

That concludes part 3, in part 4 we’ll take this further and show how you can alter just about anything randomly and that includes colours, position and the values of variations. See you there!

### Video Tutorial

```//Add a random number procedure (thanks Jesus Sosa)
public int range(int min, int max)
{
return min + (int)(Math.random()*(max-min + 1));
}
public double range(double min, double max)
{
return min + Math.random()*(max-min);
}```