Avatar of sarah_siu
sarah_siu
Flag for United States of America 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...:

<%@ 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>

Open in new window


If anyone can provide a pseudo code, that will be very helpful!

Thanks!
JavaScriptJavaWeb Languages and Standards

Avatar of undefined
Last Comment
HonorGod

8/22/2022 - Mon
SOLUTION
krakatoa

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
CEHJ

ASKER CERTIFIED SOLUTION
HonorGod

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
sarah_siu

ASKER
Thanks for your help!
krakatoa

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
HonorGod

Thanks for the grade & points.

Good luck & have a great day.