24
$\begingroup$

Is it possible to generate a random number for use in the node editor?

I am aware of the Object Info node, but I want a random number which I have more control over.
Ideally I could change it with some sort of "seed" vale and be able to define limits for maximum and minimum values.

How is this possible?

$\endgroup$
2

5 Answers 5

11
$\begingroup$

There is now a White Noise Texture node, which takes input Coordinates and outputs a totally different value (either RGB or between 0 and 1) for even the slightest variation in input.

The input can be set to use 1D, 2D, 3D or 4D. If using 4D, the 4th input, W, can be used as an additional seed to the node.

enter image description here

$\endgroup$
3
  • $\begingroup$ Oops, just duped you. And in the wrong place. Will link here, and delete mine after a bit. $\endgroup$
    – Robin Betts
    Feb 27, 2021 at 11:10
  • 1
    $\begingroup$ @RobinBetts No biggie !! I love me some seizure inducing GIFs :D $\endgroup$
    – Gorgious
    Feb 27, 2021 at 14:41
  • 1
    $\begingroup$ that's what i was looking for! +1 $\endgroup$
    – Chris
    Oct 8, 2021 at 7:33
22
$\begingroup$

That would be through drivers. You can add an Input->Value node to feed into other nodes or add a driver to an editable value on any other node.

A simple way to get random values is edit the value and enter #noise.random() This will give random values between 0 and 1, you can expand the entry to multiply the value if you want it larger or add a minimum value.

To get more control over the generated value you can create a script and use bpy.app.driver_namespace["name"] = funcname to provide access to any function you define. The script name must end in .py so that you can register it and auto run python scripts also needs to be enabled.

$\endgroup$
8
  • 1
    $\begingroup$ I tried using noise.random() as a scripted expression, however the debug value stayed as 0 and it did not appear to work in a render. $\endgroup$
    – gandalf3
    Mar 27, 2014 at 7:02
  • $\begingroup$ You may need to update dependencies, but one thing I have seen stop this working is if the interpolation type of the driver is set to constant. The other is not enabling auto-run python scripts, you should see a notice if that is the case. $\endgroup$
    – sambler
    Mar 27, 2014 at 23:08
  • $\begingroup$ I got it working :) I had to save the file first. Something to do with auto run perhaps? I have it enabled but with some excluded directories. $\endgroup$
    – gandalf3
    Mar 27, 2014 at 23:25
  • $\begingroup$ Does this expression evaluate on each frame or on each sample? $\endgroup$
    – Matt
    Nov 21, 2020 at 3:11
  • 1
    $\begingroup$ @Acebone It is not. You have to enable Automatic Execution of Python Scripts in User Preferences > Save&Load > Auto Run Python Scripts. Then just update the driver. Expressions can call functions. This is why this works and it is limited by default, otherwise it could be unsafe to auto-execute code from unknown sources. $\endgroup$
    – Chaos
    Feb 1, 2022 at 16:13
12
$\begingroup$

If you are texturing, there is a "random" value in the object info nodeenter image description here

Not entirely sure what your application is, but there's more info on the object info node at http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/More

Also found this post here on stack exchange: Random maps in cycles

$\endgroup$
3
  • 1
    $\begingroup$ Please summarize the links you have referenced in your answer. If the link goes down, so does your answer. $\endgroup$
    – CharlesL
    Dec 9, 2013 at 14:14
  • $\begingroup$ gandalf3 already mentioned this. $\endgroup$
    – Samoth
    Apr 17, 2016 at 19:47
  • 1
    $\begingroup$ There it is - a random number, no shenanigans. Best answer, at least for my purpose :) $\endgroup$
    – Acebone
    Oct 22, 2021 at 11:18
9
$\begingroup$

I took a little different approach. I added a "value" node. Then key framed it to 0.5 at frame 1 and also to 0.5 at the last frame. Then using the F-curve modifier, I added noise to the F-curve. This has worked well for me to use with flickering lights and such.

$\endgroup$
2
$\begingroup$

Another approach, if you don't need it to be truly random, is to take the same random output from the object info node, pass it through math.multiply and multiply it by some quite large value (100?), then through a math.modulo with modulo 1.

screenshot of nodes, with the same random output of an object info node feeding to two separate inputs, one via a multiply node and a modulo node

I think for almost all purposes this is going to seem like a brand new random number. At least, when you wouldn't notice a minute difference of the main random number. We're essentially chopping up the digits of the random number we were given into chunks, and using each chunk as a different random number.

So say we got 0.9172352114 as our random number, we can use that is is for one purpose, then multiply and modulo it to get 0.72352114 as our second. We could do it again and get 0.352114 is our third one.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .