Jump to content
Sign in to follow this  
tdtd

Constant Random Number

Recommended Posts

I need to generate a random integer based on a user data integer.

I only want the random number to change when the user data changes.

Can anyone advise the best way to go about setting this up?

 

Thanks,

Tom

Share this post


Link to post
Posted (edited)

Is this happening during animation ? If so, you could use a memory node to compare current value to value on previous frame and unfreeze the random number if different.

freeze2.thumb.png.c3adb2d27f6ce64244655d7e8867d336.png

 

 

the data change should be step

freeze2.c4d

 

Edited by jed
new file - error at frame 0

Share this post


Link to post
Author of the topic Posted
5 hours ago, jed said:

Is this happening during animation ? If so, you could use a memory node to compare current value to value on previous frame and unfreeze the random number if different.

freeze2.thumb.png.c3adb2d27f6ce64244655d7e8867d336.png

 

 

the data change should be step

freeze2.c4d 177.57 kB · 1 download

 

 

Thanks Jed this is a very clear and useful example that i'm sure i'll go back to a lot.

 

Much appreciated.

Share this post


Link to post

Or use the python node: 

import c4d
import random
#Welcome to the world of Python


def main():
    global Output1
    random.seed(Input1)
    Output1 = random.random() * 100

Create the python node, copy&paste this code, delete Input2 and feed the User Data into Input1. Output1 will give you a random number between 0 and 100 (in this case). 

Share this post


Link to post

@Havealot neat use of seed to stop the value changing every frame.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...