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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:31:20+00:00 2026-05-27T14:31:20+00:00

say i generated a set of random numbers and put them into an array,

  • 0

say i generated a set of random numbers and put them into an array, (pre-sorted for simplicity) i’ll use javascript to show the math:

var vals = new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,...,10000);

then in a loop, i created a random number to serve as an index:

for(i=0;i<10000;i++){
    var random_index = Math.floor(Math.random() * 10000);
    var result = vals[random_index];
}

if you looked at this output on any kind of graph, the results (with enough iterations through that loop, will look pretty random and balanced)

what I want, is for the results of each access to favor smaller numbers, which incidentally here is array elements with a lower index.

for a visual example, imagine you’re trying to plot on a map where the fragments of a firework fell. most of those fragments would fall randomly within a vicinity but have a heavier concentration towards the middle. that’s a bit of an over-complicated example since it’s taking another dimension into account and uses physics to achieve the result, but it’s the same principal.

what operation should i perform on the random_index variable to make it ‘favor’ smaller numbers?

  • 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-27T14:31:21+00:00Added an answer on May 27, 2026 at 2:31 pm

    There are any number of things you can do.

    For instance:

    Math.floor(Math.sqrt(Math.random() * 10000^2));
    

    The real question is, what kind of distribution do you want?

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

Sidebar

Related Questions

here is code, which fills two dimensional array with random genarated numbers in range
I need to generate a set of coordinates in Erlang. Given one coordinate, say
Say I have a binary file (generated with Java) containing a 32 bit int
Let's say I have a web site for hosting community generated content that targets
I have a randomly generated vector, say A of length M . Say: A
Any info out there on how to print the generated charts in say PDF
I'm trying to use EF4 and the supposedly new feature of having GUIDs generated
Let's say I have a table of users set up like this: CREATE TABLE
We were given a set of ASMX services to consume. We have no say
Say I have this MYBATIS statement: <insert id=insertValue resultType=car > BEGIN TRANSACTION INSERT INTO

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.