# $rand() modifications

**URL:** <https://community.mp3tag.de/t/rand-modifications/60119>\
**Category:** Support\
**Created:** [February 19, 2023, 2:06am UTC](https://community.mp3tag.de/t/rand-modifications/60119 "2023-02-19T02:06:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chayes](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/e0b2c6/32.png) [@chayes](https://community.mp3tag.de/u/chayes)\
**Post date:** [February 19, 2023, 2:06am UTC](https://community.mp3tag.de/t/rand-modifications/60119/1 "2023-02-19T02:06:44Z")

</div>

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.

🙂

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [February 19, 2023, 6:27am UTC](https://community.mp3tag.de/t/rand-modifications/60119/2 "2023-02-19T06:27:35Z")

</div>

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

> [@chayes](#):
>
> with those below 100 stating with 0

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:

> **[Main Window – Mp3tag Documentation](https://docs.mp3tag.de/getting-started/main-window/#sorting)**
>
> Detailed explanation of the interface elements in Mp3tag's main window, i.e., File List, Tag Panel, Filter, Status Bar, Menus, and Toolbar. Mp3tag is the universal Tag Editor.

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.

---

<div class="post-metadata">

**Author:** ![chayes](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/e0b2c6/32.png) [@chayes](https://community.mp3tag.de/u/chayes)\
**Post date:** [February 19, 2023, 2:50pm UTC](https://community.mp3tag.de/t/rand-modifications/60119/3 "2023-02-19T14:50:51Z")

</div>

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

😀

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [February 19, 2023, 2:53pm UTC](https://community.mp3tag.de/t/rand-modifications/60119/4 "2023-02-19T14:53:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chayes](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/e0b2c6/32.png) [@chayes](https://community.mp3tag.de/u/chayes)\
**Post date:** [February 19, 2023, 3:09pm UTC](https://community.mp3tag.de/t/rand-modifications/60119/5 "2023-02-19T15:09:21Z")

</div>

> [@ohrenkino](#):
>
> $num($mod($rand(),10000),3)

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.

🙂

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [February 19, 2023, 3:11pm UTC](https://community.mp3tag.de/t/rand-modifications/60119/6 "2023-02-19T15:11:56Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![chayes](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/e0b2c6/32.png) [@chayes](https://community.mp3tag.de/u/chayes)\
**Post date:** [February 19, 2023, 8:39pm UTC](https://community.mp3tag.de/t/rand-modifications/60119/7 "2023-02-19T20:39:05Z")

</div>

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

🙂

---

<div class="post-metadata">

**Author:** ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)\
**Post date:** [March 21, 2023, 8:39pm UTC](https://community.mp3tag.de/t/rand-modifications/60119/8 "2023-03-21T20:39:14Z")

</div>

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