troubleshooting Question

random non-repeat number generator

Avatar of sarah_siu
sarah_siuFlag for United States of America asked on
JavaScriptJavaWeb Languages and Standards
6 Comments2 Solutions1079 ViewsLast Modified:
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...:

<%@ 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>
        &nbsp;<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!
ASKER CERTIFIED SOLUTION
HonorGod
Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros