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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:11:19+00:00 2026-05-26T21:11:19+00:00

I want to generate eight bit (uint8_t) random numbers so that I exclude a

  • 0

I want to generate eight bit (uint8_t) random numbers so that I exclude a set of well known numbers which have already been specified. Basically numbers from 0x00 – 0xFF but I have certain numbers within that range that I do not want to appear.

I am thinking of just populating a vector with the numbers allowed and pick a (pseudo) random index and use that one.

I suspect their may be serious short comings with this so looking for leads/advice. The solution need not be rocket science grade but just simple enough to “appear” random 🙂

EDIT: I do not want to use external libraries like boost as I am working on ARM embedded solution

EDIT: I do not have support for C++11

  • 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-26T21:11:20+00:00Added an answer on May 26, 2026 at 9:11 pm
    #include <iostream>
    #include <algorithm>
    #include <ctime>
    
    int main()
    {
        srand(time(0));
        int exclude [] = {4,6,2,1};
        // Test Values for Exclude
        std::sort(exclude, exclude + 4);
    
        int test = 0;
        for (int i = 0; i < 50; ++i)
        {
            // While we haven't gotten a valid val.
            while ( std::binary_search(exclude, exclude + 4, test = (rand() % 256))); 
            std::cout << test << std::endl; // Print matched value
        }
        return 0;
    }
    

    I think this will work a little bit faster than @IceCoder’s solution.

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

Sidebar

Related Questions

I want to generate random numbers manually. I know that every language have the
I want to generate random colours which can be attractive in pie charts.I have
I want to generate the random numbers using this loop. When i runs the
I want to generate heat map from a set of data which is latitude
I want to generate a PDF that will contain an image. so i already
Let's say I have a class of 30 students and want generate every possible
I want to generate a summary of the files that are in one tree
I want to generate a random floating point number between 0.000000000000000 and 0.999999999999999 .
I want generate a list of numbers from 0000 to 9999. I would then
I want to generate all combination of length r from a set [0...(n-1)] So

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.