Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6814273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:40:11+00:00 2026-05-26T20:40:11+00:00

What happens is that if a user clicks on the ‘Get Session Id’ button.

  • 0

What happens is that if a user clicks on the ‘Get Session Id’ button. It displays a random string which will represent the sessionId. This works fine. My problem is that at moment I have 5 strings which are “AAA”, “AAB”, “AAC”, “AAD” and “AAE”. Now I want the strings to go on all the way to “ZZZ”.

It will take me an age and a lot of coding to write out all of the strings from “AAA” to “ZZZ”. What I want to know is that is there a way where I can display all the strings between “AAA” and “ZZZ” without requiring entering in all of the strings manually?

Below is my code:

<head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <title>Create a Session</title>
        <script type="text/javascript">

var randomStrings = [
        "AAA",
        "AAB",
        "AAC", 
        "AAD",
        "AAE",
    ];

    function getSession() {

var randomDiv = document.getElementById("randomStrings");

          randomIndex = Math.round(Math.random()*(randomStrings.length-1));
          newText = randomStrings[randomIndex];
          randomDiv.innerHTML = newText;
}

</head>

<body>
<form action="create_session.php" method="post" name="sessionform">
 <table>
          <tr>
          <th>1: </th>
          <td><input id="sessionBtn" type="button" value="Get Session ID" name="sessionid" onClick="getSession()" /></td>   <!-- Get Session ID here-->
          <td id="randomStrings"></td>
          </tr>
          </table>
</form>
</body>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:40:11+00:00Added an answer on May 26, 2026 at 8:40 pm

    For what you’re doing here, it will be way more expensive than necessary to generate all the possible strings, then choose one randomly. If you do it that way, you will have to generate 17,576 (26^3) strings, just for a single random three-letter string. You can, instead, just generate a single random string instead, one character at a time.

    var alphabet = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ];
    
    function generateRandomString(strLength) {
        var output = "";
        for (var i = 0; i < strLength; i++) {
            var randomIndex = Math.floor(Math.random() * alphabet.length);
            output += alphabet[randomIndex];
        }
        return output;
    }
    
    function getSession() {
        var randomDiv = document.getElementById("randomStrings");
        newText = generateRandomString(3);
        randomDiv.innerHTML = newText;
    }
    

    This solution also scales way better. To generate all the possible strings and choose one, your runtime would be O(26^n), where n is the number of characters in the string. The runtime of this solution (building the string character by character) is O(n), where n is the number of characters in the string.

    This means if you decide you need more session IDs (if more users are using your application), you can do so easily. A 5-character session ID would take 11,881,376 iterations, if you were to build all the possibilities beforehand. It would take 5 iterations building one possibility on-the-fly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering about one thing - let's assume that the user clicks a button,
One of the features is that when a user clicks on something, something happens.
If a user clicks on a button that does a post (lets say it
Suppose all that happens initially in a client swf is a user clicks a
I want to disable a hyperlink so that if user clicks on the link,
I have a UIView that I want to load when the user clicks a
I am developing an ASP.Net application that will need to verify that the user
When the user clicks on the button with id=cancel , they are redirected to
I'd like to have a view appear when the user clicks a button. The
It often happens that characters such as é gets transformed to é , even

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.