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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:13:25+00:00 2026-05-20T23:13:25+00:00

Basically I pick a random number between 0-24: Math.floor(Math.random() * myArray.length); // myArray contains

  • 0

Basically I pick a random number between 0-24:

Math.floor(Math.random() * myArray.length); // myArray contains 25 items

Lets say it comes out to be 8. Now I want to get another number in the same range 0-24 but this time, I do not want an 8. The next time, I might roll a 15. Now I want to roll again but I don’t want an 8 or 15. The way I am handling this now is by using do while loops and if the number comes out the same, I just reroll.

This is a small portion of my homework and I, in fact, have it working to meet all the requirements so I guess you could say this is for my own personal benefit so I can write this properly and not end up on “the daily wtf”.

  • 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-20T23:13:26+00:00Added an answer on May 20, 2026 at 11:13 pm

    Set an array with all the values (this is only a valid option if you’re only doing small numbers, like the 25 in your example), like this:

    var array = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24];
    

    then, pick a random number between 0 and the array length:

    var num = Math.floor(Math.random() * array.length);
    

    remove that index number from the array:

    var roll = array.splice(num, 1);
    

    Javascript splice() removes indexed items from an array and returns the item(s) as an array. Perfect for your use.

    Grab the first index from the roll, since we only cut 1 out anyway:

    var yourNumber = roll[ 0 ];
    

    Keep doing for as many rolls as you want. Also, you might want to store the original array as a copy so that you can “reset” the numbers easily.

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

Sidebar

Related Questions

i basically just want to pick a random value in a string split by
Basically, I want to get a list of all installed apps and pick one
Basically, the input field is just a string. People input their phone number in
I'm adding an if statement to my database abstraction layer to pick out any
I would like to create an ImagePicker control that lets users pick an image
I have a Django website that basically just displays a bunch of items from
Basically I'm using datepicker from jQuery to have my client pick a date. I
Nothing too complicated, basically I just want to pick an element from the array
here is my first program it basically says stuff out loud and in different
We are building a configurator application for conveyors. Basically user comes in and picks

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.