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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:09:38+00:00 2026-06-12T14:09:38+00:00

I have looked around and cannot find a working solution to my problem. Background

  • 0

I have looked around and cannot find a working solution to my problem.

Background — the intended use is an easy to form for a live rpg group for calculating successes of a downtime action. By entering numbers into given form fields, the script calculates the total number of “dice” with values between 1 – 10 to be used. There is also a difficulty threshold that needs to be met on each “roll” of the “dice” to be considered a success.

I am having difficulties generating random numbers using totalDice as the size of the array. Once I have that down, I will need to find a way to count and display the total number of random numbers greater than the given difficulty threshold.

For a working example of what I have so far, see here.

I have a var = totalDice which provides the size of the random array. The values of the random numbers are 1 – 10.

For example, if totalDice= 220, I need 220 random numbers generated between 1 and 10.
Then I have var = totalDiff which provides a threshold that I need to compare against the random numbers generated. I need to find a way to take the array generated and count the number of instances that are => totalDiff.

Example: totalDice = 220, totalDiff = 6, totalSuccesses = x, where x = the number of elements => 6.

Any help is greatly appreciated.

  • 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-06-12T14:09:39+00:00Added an answer on June 12, 2026 at 2:09 pm

    Break this into chunks, that’s what functions are for.

    var roll = function() {
        return Math.floor(Math.random() * 10 + 1);
    };
    
    var getResult = function(difficulty) {
        return roll() >= difficulty;
    };
    
    var getAllResults = function(totalDice, difficulty) {
        var arr = [];
        for (var i = 0; i < totalDice; i++) {
            arr.push(getResult(difficulty));
        }
        return arr;
    };
    

    Check:

    var results = getAllResults(220, 6);
    var t = 0;
    var f = 0;
    
    for (var i = 0; i < results.length; i++) {
        if (results[i]) { 
            t++;
        } else {
            f++;
        }
    }
    console.log('total rolls', 220);
    console.log('total result count (expected 220)', results.length);
    console.log('boolean results (expected 220)', t + f);
    console.log('successes', t);
    console.log('failures', f);
    console.log('raw results array', results);
    

    Edit: If you just want the number of successes, make another function to count them:

    var getSuccesses = function(results) {
        var successes = 0;
        for (var i = 0; i < results.length; i++) {
            if (results[i]) { 
                successes++;
            } 
        }
        return successes;
    };
    
    //Count successes for 175 die rolls at difficulty 8:
    var s = getSuccesses(getAllResults(175, 8));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've looked around but have yet to find a great solution the the following
I have looked around but cannot find anything that answered this particular question related
I have looked around and simply cannot find a way to open a linked
I have looked around the net and cannot find a project for this game.
Got this error for the first time, I have looked around and cannot find
I have looked around but cannot seem to find anything quite like i need.
Sorry if this is obvious but have looked around and can't get this working:
I've looked around the forum, but cannot seem to find a definite answer to
I have looked around on here but can not find out why this is
I have looked around the internet for 3 hours now looking for a solution

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.