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 7065259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:56:04+00:00 2026-05-28T04:56:04+00:00

I am currently working on a random number generator script that will generate three

  • 0

I am currently working on a random number generator script that will generate three numbers. The first two numbers will be used to pick a “cell” in a “table” by referencing the row and column. Within each cell are two numbers to choose from. The third number will then determine which of the two numbers to select. I have figured out most of this but I am having problems with the last part.

My “solution” was to create twenty arrays, and within each array are twenty more arrays. Here is an example of the first array:

In the header I have the following:

Scripts to generate the first two numbers:

var randOne20 = Math.floor(Math.random()*20);
var randTwo20 = Math.floor(Math.random()*20);

Here is the first row of the 20 arrays:

var lvl1Roll1 = [[ 1,0 ],[ 1,1 ],[ 1,2 ],[ 1,3 ],[ 1,4 ],[ 1,5 ],[ 1,6 ],[ 1,7 ],[ 1,8 ],[ 1,9 ],[ 1,10 ],[ 1,11 ],[ 1,12 ],[ 1,13 ],[ 1,14 ],[ 1,15 ],[ 1,16 ],[ 1,17 ],[ 1,18 ],[ 1,19 ]];

The second row would be “lvl1Roll2” and the third would be “lvl1Roll3” etc. all the way up to “lvl1Roll20.”

In the body I have the following script:

var randOne = randOne20 + 1;

document.write(window['lvl1Roll'+randOne][randTwo20]);

The randOne variable is used to select the appropriate row.

I can figure out how to select a specific cell (using the randTwo20 variable) but I have no idea how to then select the first or the second number within each cell.

Now, just to clarify, I have not listed the third random number generator code because at the moment I am just trying to figure out how to select either the first or second number within each cell. Once I figure that out I can just use an if/else statement.

Also, if I did not want to print out the number but select it as a variable how would I do that?

Thank you for any and all help!

Take care and have a great day….

ciao,
john.

  • 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-28T04:56:05+00:00Added an answer on May 28, 2026 at 4:56 am

    I’m really not sure what you’re trying to do, but… Getting the first of second element of an array is as simple as arr[0] and arr[1], like so:

    // First:
    document.write(window['lvl1Roll'+randOne][randTwo20][0]);
    
    // Second:
    document.write(window['lvl1Roll'+randOne][randTwo20][1]);
    

    To randomize, just follow the same pattern as before, but use Math.round instead of Math.floor and don’t multiply by 20:

    var randOne20 = Math.floor(Math.random()*20);
    var randTwo20 = Math.floor(Math.random()*20);
    var randOne = Math.round(Math.random());
    
    document.write(window['lvl1Roll'+randOne20][randTwo20][randOne]);
    

    One more thing, though: you don’t need to put the different rows in separate variable. You can just make it one big array:

    var lvl1Roll = [
        [
            [ 1,0 ], [ 1,1 ], [ 1,2 ], [ 1,3 ], [ 1,4 ], [ 1,5 ], [ 1,6 ], [ 1,7 ], [ 1,8 ], [ 1,9 ], [ 1,10 ], [ 1,11 ], [ 1,12 ], [ 1,13 ], [ 1,14 ], [ 1,15 ], [ 1,16 ], [ 1,17 ], [ 1,18 ], [ 1,19 ]
        ],
        // [ lvl1Roll2 ],
        // [ lvl1Roll3 ], etc.
    ];
    

    And use then use this to select a value from the table and put it into the variable result:

    var result = lvl1Roll[randOne20][randTwo20][randOne];
    

    And finally: I suspect that, I you were to tell us the logic behind the “rolls”, it’s quite plausible that you don’t need this “table” at all. I could be wrong, but… might it be worth posting another question about that? Just a thought.

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

Sidebar

Related Questions

I am currently working with PHP code that random selects colors: <div onclick=location.href='<?php the_permalink()
I'm currently working on a problem that requires the random selection of an element
I'm working on a .NET application in C# that will generate a variable-length string
Possible Duplicate: Random number generator not working the way I had planned (C#) I
Possible Duplicate: Random number generator not working the way I had planned (C#) I
Am currently working on an application that requires users to submit posts and comments
I`m currently working on a script, and I have the following situation. function somnicefunction()
I'm currently working on creating a new C# project that needs to interact with
I'm working with an API that wants me to generate opaque reference IDs for
I need to use random class to generate random numbers in a multi threaded

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.