IPB

Welcome Guest ( Log In | Register )

> Notice!

Please take a minute to check our Frequently Asked Questions. Use Search to reveal possible related topics.

Also make sure you've read the Forum Guidelines before posting in this forum.

 
Reply to this topicStart new topic
> $rand() function?, how does it work?
0x20
post Mar 19 2005, 17:18
Post #1


Member


Group: Members
Posts: 4
Joined: 19-March 05
Member No.: 1655
Mp3tag Version: 2.29



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! smile.gif
0x20
Go to the top of the page
 
+Quote Post
Sebastian Mares
post Mar 19 2005, 17:57
Post #2


Moderator


Group: Full Members
Posts: 2275
Joined: 15-June 03
From: Bad Herrenalb
Member No.: 496
Mp3tag Version: 2.55a



QUOTE (0x20 @ Mar 19 2005, 05:18 PM)
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! smile.gif
0x20
*


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]. smile.gif


--------------------
There are 10 types of people in this world: those who understand binary, and those who don't.
Go to the top of the page
 
+Quote Post
0x20
post Mar 19 2005, 18:00
Post #3


Member


Group: Members
Posts: 4
Joined: 19-March 05
Member No.: 1655
Mp3tag Version: 2.29



QUOTE (Sebastian Mares @ Mar 19 2005, 11:57 AM)
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]. smile.gif
*


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!
Go to the top of the page
 
+Quote Post
dano
post Mar 19 2005, 18:03
Post #4


Moderator


Group: Moderators
Posts: 5673
Joined: 4-September 03
From: Germany
Member No.: 201
Mp3tag Version: 2.58



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...


--------------------
Go to the top of the page
 
+Quote Post
0x20
post Mar 19 2005, 20:05
Post #5


Member


Group: Members
Posts: 4
Joined: 19-March 05
Member No.: 1655
Mp3tag Version: 2.29



QUOTE (dano @ Mar 19 2005, 12:03 PM)
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...
*


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... biggrin.gif
Go to the top of the page
 
+Quote Post
DetlevD
post Mar 30 2010, 18:08
Post #6


Member


Group: Full Members
Posts: 4602
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.58



QUOTE (0x20 @ Mar 19 2005, 18:18) *
... 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


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 18th April 2014 - 21:45