How to slow down the expression tdu.rand(absTime.frame+.1)

Hello everyone, I was reading the table of python expressions on the wiki and I found an expression that gets a unique random number every frame, but in each frame is very fast, I was wondering if it is possible to write an expression that I can get unique values every 100 frames.
I hope everyone can understand my question, thank you!

1 Like

I generally feel like absTime prototyping, but not ideal for actual deployment. That said, you can use a few different expressions to help make this work depending on what kind of mechanics you’re looking for.

Round does just that… rounds a number up to a set number of decimal places.

math. ceil (x )

Return the ceiling of x, the smallest integer greater than or equal to x. If x is not a float, delegates to x.__ceil__(), which should return an Integral value.

It’s worth knowing that ceil() will return an integer, while round() returns a float. Most TouchDesigner parameters don’t care about this, but if you were doing some other tricky python, it’d be worth knowing if you were working with a float or int depending on the operation you were trying to achieve.

1 Like

Hello, as you said @raganmd sometimes abstime are not the ideal expression to get some value, let’s think I don’t want exponential numbers, but I want to get some random number in a kind of specified range… so I tried to fit math.ceil with the expression tdu.rand(absTime.frame*0.01) so I got to : *math.ceil(tdu.rand(math.ceil(absTime.frame*0.01))360)
I had to write math.ceil twice why wasn’t me turning integer values, plus I multiplied by 360 why is the range I need to vary…
To explain better, my project is actually to vary the rotation of an internal line of a dodecagon but still, I would like these numbers to be divisible by 12 to generate me rotation angles compatible with dodecagon, because of formula α (angle) = 360/ number of faces =12
.
.
.
Thank you.
Decagonvideo-1

Ahh - I see where you’re going @Rawlim.

Something like this might be interesting for you then:

Starting with our pattern CHOP - we set this up so that the length of our pattern is derived from the number of divisions in our circle. Next we’ll make sure that our amplitude is 1 less our length, and that we’re outputting an integer.

You can see in the chop to DAT that this gives us a ramp of 0 to 11

Next in a math CHOP we can make sure that multiply each of these values by 360 / the number of divisions in our circle:

These rotation values will make sure that our line points to a vertex on our circle.

We can then put these in a random order with a sort CHOP:

Using a timer and a look up we can set the interval between changes, and use the resulting cycles from our timer to look up one of these random points in our sort CHOP:

I think this is closer to what you’re looking for, and hope it helps.

Take a look at the file here to see how this is all working:
random-rotation-to-known-points.toe (4.8 KB)

3 Likes

This is a pretty good explanation @raganmd, this is exactly what i was trying to do… thank you very much