random() and noise()

I think I understand that random gives any number from the range you give inside the () ex. 0 to 50 5,8,41 ?

as for noise it also generates random numbers but at a nearer range numbers ex. 0 to 50 45,48,41 ?

can noise be solely independent ? because when I do

float x = random(50); println(x);

it generate numbers in the console

while doing

float x = noise(50); println(x);

only give same single numbers

Tagged:

Answers

  • Check the reference. Whilst the parameter in random() defines the range of returned numbers; the parameter in noise() is a 'coordinate' to a 'predefined' random number; so if you always pass the same parameter value you will always get the same output (though if I've understood correctly this will change each time you run the sketch).

  • I dont really understand the questions. But I guess you mean to get different numbers from both functions. If both generate random numbers and are the same, then you can make a seed for one of the functions like: int seed = 0; int randomNumber = 0; int maxRange = 3; seed = second(); // Get the actual second from the time of your machine. randomNumber = int(1 + random(seed) % maxRange); // From <---0---(1---2---3)---4---5---> and save it as an integer.

  • No, the parameter of random() is the maximum range. If you want to set the seed of the random() method use randomSeed(): https://www.processing.org/reference/randomSeed_.html

  • I use this method in two of my programs and works really good. It is used in C++ too in a similar way. For maximum range you can use diferrent methods like 1. int dice = int(random(1, 7)); 2. int dice = int(1 + random(6)); 3. as I posted before in here.

Sign In or Register to comment.