|
Posted by Steve on 10/15/35 12:00
"Fred Atkinson" <fatkinson@mishmash.com> wrote in message
news:up5po3t6dgt09e7lqknlu0gre57emlvrfb@4ax.com...
> I've written a PHP script that randomly selects a sound file
> to play for the BGSOUND tag. It appears below. All you have to do is
> place it between the <head> and </head> tags on a PHP Web page.
>
> <?php
> $array = array("sound_1.wav",
> "sound_2.wav",
> "sound_3.wav");
> $n = rand (0, 2);
> $sound_file = $array[$n];
> echo "<bgsound src=\"$sound_file\">\n"
> ?>
>
> The problem is that when I test it, it seems to favor the
> first and the last sound file and rarely plays the second one.
>
> Is there a better way to make the random number selection more
> evenly distributed?
>
> Before you start jumping on me about music in the background,
> that's not what I am doing. Go to http://www.wb4aej.com for a working
> example. I've got a test page (with a refresh button) on
> http://www.wb4aej.com/random_wav.php . If you don't copy Morse code,
> you probably won't understand the different sounds except that the
> first few characters of each sound file are a little different. Each
> file plays for only a few seconds and stops.
>
> I've also added links to the test page so you can play the
> random files individually.
you should be using mt_rand instead. you can also increase the pool...then,
get the result to apply, i.e. use %
$key = mt_rand(0, 10000) % count($array);
echo 'bgsound src="' . $key . '" />';
[Back to original message]
|