Uutiset:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu
Advertisement:

random word generator

Aloittaja Cat McFarlane, syyskuu 23, 2013, 08:39:43 IP

« edellinen - seuraava »

Cat McFarlane

Hiya  :)

K@ pointed me in the direction of a word generator, which people on the art forum love as drawing inspiration, and which I can base art games around. Have put it into an html simpleportal blcok ... 2.0.5 smf, dsden.org. This is the text (519 words entered alphabetically, so far). Issue I have is that often the words are coming up in alphabetical order rather than really randomly, and I want to be sure the art games don't get stuck on a loop, with everyone only getting early words and the same alphabetical words etc.

This was posted under the code, but am not sure how to do the Math code ... "you need javascript to access the wordfile and choose a random line. Or you can use it to assign every line of that file into an array, and use Math.random() to pick a random key."

Also, the box shown in pic comes up after a few clicks, and I don't want people clicking on it, as that stops the generator working ... not sure if only I can see that, but just to be safe.

Thanks

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Random thingy</title>

<script language type="text/javascript">
<!--

function getMessage()
{
var ar = new Array(519)
ar[0] = ... 519 alphabetically here


var now = new Date()
var sec = now.getSeconds()
alert("Random thingies:\n\n" + ar[sec % 519])
}

//-->
</script>

</head>

<form>
<input type="button" name="again" value="Generate another"

onClick="getMessage()">
</form>

</body>
</html>

EDIT: tried incorporating the following instead ...

<script language="JavaScript">
<!--
var randomString = new Array ();
randomString[0] = "a random string";
randomString[1] = "another random string";
randomString[2] = "another random string";
randomString[3] = "another random string";
randomString[4] = "another random string";
randomString[5] = "another random string";
randomString[6] = "another random string";
randomString[7] = "another random string";
var i = Math.floor(7*Math.random())

document.write(randomString);
//-->
</script>

but same alphabetized results, not random across entire 519 words.

Had put at bottom of list ... var i = Math.floor((Math.random()*519)+1);

Advertisement: