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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:30:52+00:00 2026-05-30T20:30:52+00:00

I want to select a number of random words from an array to make

  • 0

I want to select a number of random words from an array to make a total amount of 36 letters.

At first I tried to select a random word and add it after checking that it’s not longer than the amount of free space we have. That was not efficient since the list would fill up and there would only be empty space left for a 2-3 letter word and it takes a long time to find such a short word.

So i decided to only choose six 6-letter words and I’m doing that by generating a random number and then incrementing it by 1 until we find a 6 letter word. It’s pretty fast, but the words aren’t really that random, often I get words that start from the same letter or only words that start with letters in sequence like a,b,c or x,y,z.

srand ( time(NULL) );
for(int i=0;i<6;i++)
{
    randNumb = rand()%dictionary.size();
    while(dictionary.at(randNumb).length() != 6)
    {
        randNumb++;
    }
    a << "/" << dictionary.at(randNumb) << "/";
}

I would like to choose words with different lengths but in favor of performance I’ll settle with just the 6-letter words but then i would at least want them to be more randomly selected.

  • 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-30T20:30:54+00:00Added an answer on May 30, 2026 at 8:30 pm

    The rand() function generates a number between 0 and RAND_MAX.

    If RAND_MAX is defined as 32767, then you will not access elements in your dictionary (array?) with indices greater than that.

    If you need to generate a random number greater than RAND_MAX, then think about summing the result of n calls of rand(), such that n * RAND_MAX >= dictionary.size(). The modulus of this result is then guaranteed to give an index that falls somewhere in the bounds of the entire dictionary.

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

Sidebar

Related Questions

I have 5 INT variables with numbers. I want select one random number from
I want to select four random images from a folder which contains a number
I want to write a map/reduce job to select a number of random samples
I have an Array of number values, and I want to randomly select a
I want to select all rows of a table followed by a random number
I've got an associative array in PHP and want to select a random key/value
I want to select a number of email addresses and then send an email
i have users table and i have posts table i want select from users
I want to SELECT a formatted date string from a datetime type in SQL
I want to select all categories from a webservice. The webservice does not have

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.