bilwebore Posted November 15, 2007 Share Posted November 15, 2007 Obtaining new numbers from a randomly filled dynamic arrayThe following code generates a list of random numbers and displays them on the html page.<html><body><pre><script language="vbscript">Dim RanNum() ReDim RanNum(10)document.writeln("Check 1: Is RanNum an array? " & IsArray(RanNum))document.writeln("Random Numbers:")For i = 0 To 10RandomNumber = Int(50 * Rnd())x = RandomNumberRanNum(i) = xdocument.writeln(" " & i & "=" & RanNum(i))Next 'Erase RanNum(10) </SCRIPT></pre></body></html>When I rerun the program the members of the array never change. I expect to get new random numbers each time!I have placed the "erase" function at numerous places in the code, to no avail. How can I get this code to generate and print new numbers each time the program is run?Bill Link to comment Share on other sites More sharing options...
Reg Edit Posted November 17, 2007 Share Posted November 17, 2007 ...When I rerun the program the members of the array never change. I expect to get new random numbers each time!I have placed the "erase" function at numerous places in the code, to no avail. How can I get this code to generate and print new numbers each time the program is run?BillIn the computing world, there's a tradition of random not being random unless you take some extra action to make it so! In VBScript, you need to use the Randomize statement. It says about it here in the tutorial. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.