ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Expression - random numbers with decimal point

FAQ   •   VIEW ALL
 Expression - random numbers with decimal point on Mar 7, 2014 at 9:18:31 am

Hello

Firstly can I say I am new to expressions. However I would like to know if there is a simple way of generating a random number with two further numbers after the decimal point.

e.g. 15.17

I have used the 'Character Offset' with a wiggle command - wiggle(1,5) but this only produces a two digit number with no decimal.

Does anyone know a work around?

Thanks
Rob

 Re: Expression - random numbers with decimal pointon Mar 7, 2014 at 4:10:43 pm

I'm not sure if this is exactly what you had in mind, but give this source text expression a try:

random(100).toFixed(2)

Dan

 Re: Expression - random numbers with decimal pointon Mar 8, 2014 at 4:14:05 pm

That's fantastic thanks - just what I wanted.

One further question. Can the speed of the random numbers be controlled? (slowed down) For example, can the time between each change of digits be extended - so the each digit is on screen for longer.

Thanks
Rob

 Re: Expression - random numbers with decimal pointon Mar 8, 2014 at 4:38:36 pm

Something like this probably:

frames = 5; // frames to hold each random number
seed = Math.floor((time - inPoint)/framesToTime(frames));
seedRandom(seed,true);

random(100).toFixed(2)

Dan

 Re: Expression - random numbers with decimal pointon Mar 9, 2014 at 2:35:55 pm

Thanks a million Dan. Perfect!

Rob