ランダムに音楽を流すアプリ
ジョーク: 完璧なランダム再生を実現するために、エンジニア5人が一晩かけて泥酔しながらシャッフルアルゴリズムを考えたそうです。
<!DOCTYPE html>
<html>
<head>
<title>ランダムに音楽を流すアプリ</title>
<script>
// 音楽のURLを配列で保持
var musicList = [
"https://example.com/music1.mp3",
"https://example.com/music2.mp3",
"https://example.com/music3.mp3"
];
// シャッフルした音楽のURLを順番に再生
var currentIndex = 0;
function playNextMusic() {
var audio = new Audio(musicList[currentIndex]);
audio.play();
currentIndex = (currentIndex + 1) % musicList.length;
// 待機時間をランダムに設定(単位はミリ秒)
var waitingTime = Math.floor(Math.random() * (20 - 3) + 3) * 60 * 1000;
// 再生が終わったら次の曲を再生する(待機時間を加味)
setTimeout(playNextMusic, audio.duration * 1000 + waitingTime);
}
// 初回の曲再生を開始
playNextMusic();
</script>
</head>
<body>
<h1>ランダムに音楽を流すアプリ</h1>
<p>ジョーク: 完璧なランダム再生を実現するために、エンジニア5人が一晩かけて泥酔しながらシャッフルアルゴリズムを考えたそうです。</p>
</body>
</html>