$rand() modifications

I use $rand() in an action to generate random numbers in the Comment field.

Does someone know of a way to modify the command so that only numbers less then 10,000 are generated , with those below 100 stating with 0?

Grateful for any advice.

:slight_smile:

You could try:
$mod($rand(),10000)

Please note that the Windows Explorer and WMP interpret 3-digit-numbers with starting 0 as octal values.

To assign a number or digits:
$num($mod($rand(),10000),3)

If you want to get files into a random order, you could also use the file list - see the documentation on sorting the file list randomly:

After sorting the entries in the file list randomly, you could assing ascending numbers.
This would have the benefit that no number would randomly appear more than once.

Many thanks ohrenkino. Brilliantly done. This solves the issue perfectly!

:grinning:

Which way did you choose in the end? The randomizer in the file list or the modified number generator?

Well , they both work , but I'm using this one at the moment -

$num($mod($rand(),10000),3)

It seems to fit as I need numbers under 100 to start with 0.

:slight_smile:

If you use the option with the order randomizer in the file list plus renumber the files afterwards, you have the full control over the number format plus you won't have any accidental/random duplicated numbers ...

You could use an action like Format value for TRACK
Format string: $num(%_counter%,3)

Very good - thanks very much for your time and expertise.

:slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.