Link to home
Start Free TrialLog in
Avatar of sarah_siu
sarah_siuFlag 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!
SOLUTION
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sarah_siu

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.