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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:31:56+00:00 2026-06-05T01:31:56+00:00

I need a simple way to randomly select a letter from the alphabet, weighted

  • 0

I need a simple way to randomly select a letter from the alphabet, weighted on the percentage I want it to come up. For example, I want the letter ‘E’ to come up in the random function 5.9% of the time, but I only want ‘Z’ to come up 0.3% of the time (and so on, based on the average occurrence of each letter in the alphabet). Any suggestions? The only way I see is to populate an array with, say, 10000 letters (590 ‘E’s, 3 ‘Z’s, and so on) and then randomly select an letter from that array, but it seems memory intensive and clumsy.

  • 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-05T01:31:57+00:00Added an answer on June 5, 2026 at 1:31 am

    Not sure if this would work, but it seems like it might do the trick:

    1. Take your list of letters and frequencies and sort them from
      smallest frequency to largest.
    2. Create a 26 element array where each element n contains the sum of all previous weights and the element n from the list of frequencies. Make note of the sum in the
      last element of the array
    3. Generate a random number between 0 and the sum you made note of above
    4. Do a binary search of the array of sums until you reach the element where that number would fall

    That’s a little hard to follow, so it would be something like this:

    1. if you have a 5 letter alphabet with these frequencies, a = 5%, b = 20%, c = 10%, d = 40%, e = 25%, sort them by frequency: a,c,b,e,d
    2. Keep a running sum of the elements: 5, 15, 35, 60, 100
    3. Generate a random number between 0 and 100. Say it came out 22.
    4. Do a binary search for the element where 22 would fall. In this case it would be between element 2 and 3, which would be the letter “b” (rounding up is what you want here, I think)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a simple way to implement the contains function using matches . I
I need a simple way to pass a C struct to a Python function.
I need a simple way to show that results are loading.. from database, while
I need a simple way to call a function every 60 minutes. How can
I need an simple way to check whether a string that is sent to
Is there a simple way to check the type of an object? I need
i developed a very simple vb.net application and i need a way for every
I need to come up with a smarter/simpler way of doing ajax calls in
I need a simple way of checking how much ram and fast the CPU
I need a simple way or pausing a few seconds before the next line

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.