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

  • Home
  • SEARCH
  • 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 7508109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:37:18+00:00 2026-05-29T22:37:18+00:00

I am creating a simple math program with 6 different problem types. I want

  • 0

I am creating a simple math program with 6 different problem types. I want the program to randomly display one of the 6 types, but some of the problems should appear more often. I use a weighted array, but after the problem type is selected from the weighted array I am having trouble figuring out which problem type it was without using 10 or more “or” commands inside of an if statement. Here is a simplified version:

//shuffle array of 10 integers to get a random value
var rand_10 = [0,1,2,3,4,5,6,7,8,9];
fisherYates(rand_10);

//Set weightedProb
weightedProb[0] = probType[0];
weightedProb[1] = probType[0];
weightedProb[2] = probType[0];
.
.
.
weightedProb[8] = probType[0];
weightedProb[9] = probType[1];

theProblem = weightedProb[rand_10[0]];
if(rand_10[0] == 0 || rand_10[0] == 1 || rand_10[0] == 2 || rand_10[0] == 3 ||rand_10[0] == 4||rand_10[0] == 5||rand_10[0] == 6||rand_10[0] == 7||rand_10[0] == 8){
  //do something
}else if(rand_10[0] ==9){
  //do something else
}
  • 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-29T22:37:18+00:00Added an answer on May 29, 2026 at 10:37 pm

    Would a simple range comparison (> and <) be what you are after?

    e.g.

    if(rand_10[0] >= 0 && rand_10[0] <= 8){
      //do something
    }else if(rand_10[0] == 9){
      //do something else
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating simple image viewer, but I want to make a sorting of pictures
Was creating a simple console application to do some prototyping and was shocked to
I'm creating simple application, some kind of portfolio. I've heard that it's better to
Creating simple php login scripts is easy, with simple one table mysql integration. I
Creating a simple TCP server based on examples but still do not get how
I am creating a simple 2D OpenGL application but I seem to be experiencing
I am creating a simple dialogue window in C#, and want to remember where
Creating simple app using GAE / Django-nonrel (I don't think the problem is specific
Creating some simple html pages specific for the iphone, and would like to use
I am creating an iphone app with objective-c. I have a math problem I

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.