Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q706 Is it possible to randomise the selection of sound files to be played?

irt.org | Knowledge Base | JavaScript | Sound | Q706 [ previous next ]

Q706 Is it possible to randomise the selection of sound files to be played?

Try:

<HTML>
<HEAD>
<SCRIPT>
<!--
// The Central Randomizer 1.3 (C) 1997 by Paul Houle (houle@msc.cornell.edu)
// See:  http://www.msc.cornell.edu/~houle/JavaScript/randomizer.html

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
};

function rand(number) {
        return Math.ceil(rnd()*number);
};

// end central randomizer. -->

</SCRIPT>
</HEAD>
<BODY>

<SCRIPT LANGUAGE="JavaScript"><!--
document.write('<EMBED SRC="sound' + rand(9) + '.wav" HIDDEN=TRUE>');
//--></SCRIPT>

</BODY>
</HTML>

Which will play a random sound file sound1.htm to sound9.htm.


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.