(.. ), Javascript ( jsfiddle )
<a id="myButton" href="#">
click here to get random stuff
</a>
<div id="myRandomDiv">
</div>
<script type="text/javascript" charset="utf-8">
var randomStrings = [
"hello 1",
"hello 2",
"hello 3",
"hello 4",
"hello 5",
];
var randomDiv = document.getElementById("myRandomDiv");
document.getElementById("myButton").addEventListener("click", function() {
randomIndex = Math.ceil((Math.random()*randomStrings.length-1));
newText = randomStrings[randomIndex];
randomDiv.innerHTML = newText;
});
</script>
PHP ( ), :
<?php
$randomThings = array(
'random thing 1',
'random thing 2',
'random thing 3',
'random thing 4',
'random thing 5',
'random thing 6',
'random thing 7 ',
);
?>
<?php
echo $randomThings[mt_rand(0,count($randomThings)-1)];
?>
( "" ) $randomThings.
$variableName[$index] - 0,1,2,3,4,5,6.
, ( "" ) , mt_rand 0 6, $randomThings. echo .