ランダム順出力アプリ
以下に、順番をランダムに出力したい文字列を入力してください(半角スペースで区切ってください)
以下が、JavaScriptを用いて実装したプログラムです。
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ランダム順出力アプリ</title>
</head>
<body>
<h1>ランダム順出力アプリ</h1>
<p>以下に、順番をランダムに出力したい文字列を入力してください(半角スペースで区切ってください)</p>
<input type="text" id="input-text"><br><br>
<button onclick="randomize()">ランダム順で出力する</button><br><br>
<p id="output-text"></p>
<script>
function randomize() {
const inputText = document.getElementById("input-text").value.trim();
const outputText = document.getElementById("output-text");
const inputArray = inputText.split(" ").filter(str => str);
if (inputArray.length == 0) {
outputText.innerText = "入力された文字列が空です。";
return;
}
let currentIndex = inputArray.length;
let randomIndex;
while (currentIndex !== 0) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
[inputArray[currentIndex], inputArray[randomIndex]] = [
inputArray[randomIndex], inputArray[currentIndex]
];
}
outputText.innerText = inputArray.join(" ");
}
</script>
</body>
</html>
```
このプログラムでは、まずHTMLでフォームとボタンを作成し、ボタンを押すたびに`randomize()`関数が呼び出されます。
`randomize()`関数では、まず入力された文字列を取得して`inputText`に格納し、不要なスペースを削除し、半角スペースで区切って配列に格納します。文字列が空である場合は`outputText`にエラーメッセージを表示します。
次に、ランダムな配列を生成するために、Fisher-Yatesシャッフルアルゴリズムを使用して、入力された文字列をランダムな順番で並び替えます。最後に、ランダムな配列を文字列に戻して`outputText`に表示することにより、ランダムな順番で全ての文字列を排出します。
このプログラムは安全に実行できるアプリであり、入力された文字列を利用して他のサイトに遷移するなどの行為は行っていません。また、ユーザーに面白いジョークを提示する機能はありませんが、そのような機能を追加することは簡単です。たとえば、ランダムな食べ物の名前を表示するオプションなどが考えられます。