Random value within a specific range?

The object info node allows you to get a number between 0 and 1, but is there a way to get something like 5-15? I’m trying to randomize material properties for particles, but the changes are either way too subtle or way too drastic and/or in a completely wrong range.

Bonus question, is there a way to randomize mesh displacement for particles?

try to add a mat node with greater and smaller then
that will limit the range of your random functions


1 Like

Simplest math in the math node?

n = 0.0 to 1.0
lower = 5
upper = 15

value = lower + (n*(upper-lower))

That’s a bad advice for various reasons.

Firstly because it doesn’t work - you can’t limit 0 to 5 and 1 to 15. You’d have to expand the range.

Secondly if you multiply the random number generator with 100 for instance, you have numbers 0 to 100.
Limiting the result to 5 and 15 for instance would result in:

0 < n <= 5, so 5 digits to generate 5
5 < n <=15, so 10 digits to generate results from 6…15
15 < n < 100, so 85 digits to generate 15.

So the chance that the pseudorandom number generated would turn out to be anything else than 15 is rather slim.

The only correct thing to do would be to use modulo.

n = 0…1
lower = 5
upper = 15

value = ((n*1000) % ((upper-lower)+1) + lower

This would generate numbers from 5 to 15 with an equal chance.

So how would I do that in the nodes? The math node is quite simple and I’m not very good with this kind of math haha.

Hmm… 15-5 = 10, so value * 10 gives a 0-10 range. You add 5 and you get your 5-15 range. No?

In other words, plug 2 math nodes the one after other.

Three nodes… :wink:

node 1 - substract lower limit from upper limit.
node 2 - multiply node 1 with your incoming value (0.0 - 1.0)
node 3 - add the lower limit to node 2.

1 Like

That works! :slight_smile: Thank you so much! Gotta save this calculation somewhere haha.
Now I see how that previous post works too and I feel kind of silly. :stuck_out_tongue: