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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:05:34+00:00 2026-06-13T03:05:34+00:00

How to generate a code made of 4 hex digits? the code meets the

  • 0

How to generate a code made of 4 hex digits?
the code meets the following conditions:
-first and third digits are the same
-second digit is even
-third digit is larger than 9
-fourth digit is random (has no conditions)

  • 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-13T03:05:36+00:00Added an answer on June 13, 2026 at 3:05 am
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main()
    {
      int code1, code2, code4;
      srand(time(NULL)); // set random seed
      code1 = random()%6+10;   // random between 10 and 15
      code2 = random()%8*2;    // even
      code4 = random()%16;     // random between 0-15
      printf("%X%X%X%X\n",code1, code2, code1, code4);
    }
    

    There are a few things to note here. The first is that I generate 3 ‘codes’, since the third is always the same as the first.

    To generate a random number from 0-15, use random()%16 I am using type int to store these, it may not matter. When printing, I use %X and not the more common %d, as %X will print it in hex. I print four hex digits (reusing code1 of course).
    The final part is to meet your conditions.
    code1 is a random number in the range 0-5 and adds 10 to it (making it greater than 9)
    code2 is random()%8*2 which generates a random number in the range 0-7 and then doubles it (making it even)
    code4 is just a random number from 0-15

    You did not explain what to do with the generated code, so I just printed it. You could use the sprintf function if you need to print it into a string for further work.

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

Sidebar

Related Questions

i have made a code to generate 11 digit random number and i want
I use Acceleo in order to generate code with a model I have made.
Let's consider the following scenario: a function which can generate code colors from white
I'm new to PHP. I'm using the following code to generate an excel sheet
I'm using the following code to generate the background cell.backgroundView = [ [[UIImageView alloc]
I've made some function that generates an email template. Code it generates is pure
I'm trying to generate code that takes a StringBuilder, and writes the values of
When I generate code using T4 templates in Visual Studio 2010, I get the
i need to look xsd file for generate code so i need this document
I have created a UML diagram and generated a class by using Generate Code

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.