sarah_siu
asked on
random non-repeat number generator
Hi,
I am trying to create a random non-repeat number generator. on my webpage currently, I have a label and a button. My thought is when I press the button, it will generate a random number and display this number in the label. I am very new to javascript and have the following code entered into my code. How can I accomplish what I would like to do? I'm not sure what to do with the random number generator javascript code now that it's in the header of my code...:
If anyone can provide a pseudo code, that will be very helpful!
Thanks!
I am trying to create a random non-repeat number generator. on my webpage currently, I have a label and a button. My thought is when I press the button, it will generate a random number and display this number in the label. I am very new to javascript and have the following code entered into my code. How can I accomplish what I would like to do? I'm not sure what to do with the random number generator javascript code now that it's in the header of my code...:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
Random rng = new Random(); // Ideally just create one instance globally
List<Integer> generated = new ArrayList<Integer>();
for (int i = 0; i < numbersNeeded; i++)
{
while(true)
{
Integer next = rng.nextInt(max) + 1;
if (!generated.contains(next))
{
// Done for this iteration
generated.add(next);
break;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblrandnum" runat="server" Height="31px" Width="195px"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" /></div>
</form>
</body>
</html>
If anyone can provide a pseudo code, that will be very helpful!
Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help!
Thanks for the points, but I a) hope you were aiming at what HonorGod commented, rather than what you seemed to be aiming at, and b) you should have given my points to CEHJ, as I don't really want points in the JavaScript TA - (as he was right of course, also.) But on a personal level - - - - good luck with your project.
Thanks for the grade & points.
Good luck & have a great day.
Good luck & have a great day.
http://technojeeves.com/joomla/index.php/free/127-javascript-is-not-java