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:

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" "">

<html xmlns="" >
<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++)
        Integer next = rng.nextInt(max) + 1;
        if (!generated.contains(next))
            // Done for this iteration
    <form id="form1" runat="server">
        &nbsp;<asp:Label ID="lblrandnum" runat="server" Height="31px" Width="195px"></asp:Label>
        <asp:Button ID="Button1" runat="server" Text="Button" /></div>

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

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