# $rand() function?

**URL:** https://community.mp3tag.de/t/rand-function/1795
**Category:** Support
**Created:** [March 19, 2005, 3:18pm UTC](https://community.mp3tag.de/t/rand-function/1795 "2005-03-19T15:18:46Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![0x20](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/0/aca169/32.png) [@0x20](https://community.mp3tag.de/u/0x20)
#### Post date: [March 19, 2005, 3:18pm UTC](https://community.mp3tag.de/t/rand-function/1795/1 "2005-03-19T15:18:46Z")

</div>

Hi,

First, thanks to the creators of mp3tag for such an excellent product. Goodbye Tag & Rename!

I have a question about the $rand() function. Is there a way to get it to return a random number within certain parameters? For example, I want to randomize the song order in a folder so i'd like to make an action to replace the track number with $rand($num\_tracks) or something.

However $rand() does not appear to work like a typical rand() function... it just returns an integer \> 0 with no upper limit, it seems. Usually in another language one would use something like int(rand($seed) \* $upper\_limit), but that's not an option here... or am I missing something? The help file doesn't want to tell me anything more.

Thanks again! 🙂  
0x20

---

<div class="post-metadata">

### Author: ![Sebastian\_Mares](https://community.mp3tag.de/user_avatar/community.mp3tag.de/sebastian_mares/32/9285_2.png) [@Sebastian\_Mares](https://community.mp3tag.de/u/Sebastian_Mares)
#### Post date: [March 19, 2005, 3:57pm UTC](https://community.mp3tag.de/t/rand-function/1795/2 "2005-03-19T15:57:21Z")

</div>

> [@](#):
>
> Hi,
> 
> First, thanks to the creators of mp3tag for such an excellent product. Goodbye Tag & Rename!
> 
> I have a question about the $rand() function. Is there a way to get it to return a random number within certain parameters? For example, I want to randomize the song order in a folder so i'd like to make an action to replace the track number with $rand($num\_tracks) or something.
> 
> However $rand() does not appear to work like a typical rand() function... it just returns an integer \> 0 with no upper limit, it seems. Usually in another language one would use something like int(rand($seed) \* $upper\_limit), but that's not an option here... or am I missing something? The help file doesn't want to tell me anything more.
> 
> Thanks again! 🙂  
> 0x20
> 
> \<{POST\_SNAPBACK}\>

As far as I know, you cannot set the boundaries for $rand().  
If you want to randomize the track order in a folder and change the track numbers, click on the very first column (where the icons are) and then use the track numbering wizard [CTRL+K]. 🙂

---

<div class="post-metadata">

### Author: ![0x20](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/0/aca169/32.png) [@0x20](https://community.mp3tag.de/u/0x20)
#### Post date: [March 19, 2005, 4:00pm UTC](https://community.mp3tag.de/t/rand-function/1795/3 "2005-03-19T16:00:58Z")

</div>

> [@](#):
>
> As far as I know, you cannot set the boundaries for $rand().  
> If you want to randomize the track order in a folder and change the track numbers, click on the very first column (where the icons are) and then use the track numbering wizard [CTRL+K]. 🙂
> 
> \<{POST\_SNAPBACK}\>

Cool, that is also good to know. I have a bigger idea for a script that could really use a $rand() with limits, but i can use that tip now. thanks Sebastian!

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [March 19, 2005, 4:03pm UTC](https://community.mp3tag.de/t/rand-function/1795/4 "2005-03-19T16:03:22Z")

</div>

Try $num($left($rand(),2),2) as solution.  
Do you also get the same numeres from the $rand() funktion?  
41 18467 6334 26500 19169 15724...

---

<div class="post-metadata">

### Author: ![0x20](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/0/aca169/32.png) [@0x20](https://community.mp3tag.de/u/0x20)
#### Post date: [March 19, 2005, 6:05pm UTC](https://community.mp3tag.de/t/rand-function/1795/5 "2005-03-19T18:05:23Z")

</div>

> [@](#):
>
> Try $num($left($rand(),2),2) as solution.  
> Do you also get the same numeres from the $rand() funktion?  
> 41 18467 6334 26500 19169 15724...
> 
> \<{POST\_SNAPBACK}\>

that's a good idea, but still you could end up with track numbers higher than the total tracks in the album.

i suppose it's not a big deal... 😃

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [March 30, 2010, 3:08pm UTC](https://community.mp3tag.de/t/rand-function/1795/6 "2010-03-30T15:08:12Z")

</div>

> [@0x20](#):
>
> ... I have a question about the $rand() function. Is there a way to get it to return a random number within certain parameters? ...

Following example returns random numbers from 0 to 10:  
$mod($rand(),11)

Following example returns random numbers from 1 to 11:  
$add($mod($rand(),11),1)

Following example returns random numbers from 5 to 15:  
$add($mod($rand(),11),5)

Following example returns random numbers from -5 to 5:  
$sub($mod($rand(),11),5)

DD.20100330.1907.CEST

---

<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: [February 9, 2026, 12:19pm UTC](https://community.mp3tag.de/t/rand-function/1795/7 "2026-02-09T12:19:21Z")

</div>


