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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:42:26+00:00 2026-06-07T02:42:26+00:00

Using Javascript, how can I generate random numbers that are skewed towards one end

  • 0

Using Javascript, how can I generate random numbers that are skewed towards one end or the other of the distribution? Or ideally an point within the range?

For context: I’m creating a UI that has uses a grid of random grey squares. I’m generating the grey’s RGB values using Math.random() but would like to be able to skew the greys to be on average darker or lighter while still having the full range from black to white represented.

(I think this is a similar question to Skewing java random number generation toward a certain number but I’m working with Javascript…)

Any help 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-07T02:42:28+00:00Added an answer on June 7, 2026 at 2:42 am

    Raise Math.random() to a power to get a gamma curve – this changes the distribution between 0 and 1, but 0 and 1 stay constant endpoints.

    var r= Math.pow(Math.random(), 2);
    var colour= 'rgb('+r*255+', '+r*255+', '+r*255+')';
    

    For gamma>1, you will get darker output; for 0<gamma<1 you get lighter. (Here, ‘2’ gives you the x-squared curve; the equidistant lightness would be ‘0.5’ for the square-root curve.)

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

Sidebar

Related Questions

How can I generate some unique random numbers between 1 and 100 using JavaScript?
In javascript we can generate a random number using Random() function. But how to
How can I manipulate using JavaScript (JQuery) a site, not in my server, that
Using JavaScript, how do I create an HTML table that can "accept" numeric matrix
I'm using javascript to generate a high resolution grid for an image that I
Is there a way I can generate switch statements in jquery/javascript by using some
I'm using play-1.2.4, but i found the javascript file can't generate urls with the
I want to click the video on this page http://37.128.191.200/?640 using JavaScript but can't
Possible Duplicate: Prevent any form of page refresh using jQuery/Javascript how can i prevent
I'm trying to make a drop down menu using javascript/jquery but can't get my

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.