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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:01:57+00:00 2026-06-03T15:01:57+00:00

Given an integer range R = [a, b] (where a >=0 and b <=

  • 0

Given an integer range R = [a, b] (where a >=0 and b <= 100), a bias integer n in R, and some deviation b, what formula can I use to skew a random number generator towards n?

So for example if I had the numbers 1 through 10 inclusively and I don’t specify a bias number, then I should in theory have equal chances of randomly drawing one of them.

But if I do give a specific bias number (say, 3), then the number generator should be drawing 3 a more frequently than the other numbers.

And if I specify a deviation of say 2 in addition to the bias number, then the number generator should be drawing from 1 through 5 a more frequently than 6 through 10.

What algorithm can I use to achieve this?

I’m using Ruby if it makes it any easier/harder.

  • 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-03T15:02:01+00:00Added an answer on June 3, 2026 at 3:02 pm

    i think the simplest route is to sample from a normal (aka gaussian) distribution with the properties you want, and then transform the result:

    • generate a normal value with given mean and sd
    • round to nearest integer
    • if outside given range (normal can generate values over the entire range from -infinity to -infinity), discard and repeat

    if you need to generate a normal from a uniform the simplest transform is “box-muller“.

    there are some details you may need to worry about. in particular, box muller is limited in range (it doesn’t generate extremely unlikely values, ever). so if you give a very narrow range then you will never get the full range of values. other transforms are not as limited – i’d suggest using whatever ruby provides (look for “normal” or “gaussian”).

    also, be careful to round the value. 2.6 to 3.4 should all become 3, for example. if you simply discard the decimal (so 3.0 to 3.999 become 3) you will be biased.

    if you’re really concerned with efficiency, and don’t want to discard values, you can simply invent something. one way to cheat is to mix a uniform variate with the bias value (so 9/10 times generate the uniform, 1/10 times return 3, say). in some cases, where you only care about average of the sample, that can be sufficient.

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

Sidebar

Related Questions

Given below is some code in ada with TYPE_VECT_B; use TYPE_VECT_B; Package TEST01 is
I have a table containing integer values from 0 to some large number N,
Is there some limit to what I can select in a range via VBA?
Given the start and the end of an integer range, how do I calculate
I have the following function, which generates an integer in a given range: 18
Can a double (of a given number of bytes, with a reasonable mantissa/exponent balance)
I need to come up with some code that checks if a given integer
How can I can get the char representation of an integer in the range
Given an unsorted integer array, and without making any assumptions on the numbers in
Given a distance (50km) as integer: 50 And a time as string in the

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.