...

View Full Version : help with random letter generator



deathmill
03-19-2004, 01:00 AM
Hi,

script below works fine for numbers but getting it to generate a random 4 or 5 letter is a nightmare. Where is it going wrong.

thanks in advance

D

<script type="text/javascript">
<!--
var randomnumber = Math.round(Math.random()*1007700);

var randomletter = "abcdefghiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXTZ";
var randomalpha = Math.floor(Math.random() * randomletter.length);

document.write('<a href="http://www.site.com/redirect.php?id='+randomalpha+''+randomnumber+'">Link</a>');
document.write('"'+randomnumber+'"');
document.write('"'+randomalpha+'"');

//-->

</script>

Willy Duitt
03-19-2004, 01:12 AM
Firstly;
randomletter is one long string not an array so you will need to use:
charAt(randomnumber) or indexOf(randomnumber)

Secondly;
Is this a homework assignment?

.....Willy

JohnKrutsch
03-19-2004, 05:15 AM
This will give you one random letter. If wanted to get more using this method you would have to loop it:

var randomletter='abcdefg...ABCDEFG...'.split("");
var randomalpha=randomletter[Math.floor(Math.random() * randomletter.length)];
I shortened your randomletter string for brevity but you should get the idea.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum