Make your own free website on

Random MIDI player.

Every time you load this page a different MIDI will play. Well there are only 6 different MIDI's in this one so you may get a duplicate. The more MIDI's you place in this the less chance of duplication.

There's a couple of new useful things in this script. First is new Array.
var song=new Array;
This makes it so I can assign a bunch of values to the array and be able to access it later according to the number.
So in my script I have 6 MIDI addresses stored in the array. I also have the title of the MIDI's store in an array
var title=new Array;
title[1]="rainbow connection";

So now I have 6 MIDI addresses and 6 titles stored in Arrays. Now all I need is a random number between 1 and 6 to pick wich MIDI will be played.

var pl=(Math.random(1));

This assigns a random number to the variable pl. The random number is less than 1 so now we'll multiply it by 6


Now you need to round it off with this

Now you should have a random number somewhere between 1 and 6. But if the original random number was real small you might end up with a zero wich we havn't assigned anything to song[0] or title[0] wich we could have so now we must make sure pl does not equal zero.
if (pl<1){pl=1;}
so if pl is smaller than one then pl will equal one. Now we have the number and use the location statement
and then writing the title to the page.
document.writeln("<center>You are listening to "+title[pl]+"</center>");

Here is the entire Script

<script language="JavaScript">
<!-- Hide
var song=new Array;
var title=new Array;
title[1]="Rainbow Connection";
title[2]="Stairway to heavan";
title[3]="Dust in the wind";
title[4]="Don't fear the reaper";
title[5]="Nobody home";
title[6]="Theme for Voyager";
var pl=(Math.random(1));
document.writeln("<center><font color=blue>You are listening to "+title[pl]+"</font></center>");
// End Script -->

I could have place this script with in a function to be called when the page is loaded. Here is how you have a function called upon loading of a page.

<body onLoad="play()" bgcolor="#FFFFFF" text="#000000" link="#0000CC" vlink="#000066"> Just place the onLoad in you body tag to call whatever fuction you want.

Page 8, having things show up in the status bar

|| index||page 1||page 2||page 3||page 4||page 5||page 6||page 7||Page 8||