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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:42:59+00:00 2026-06-12T07:42:59+00:00

Im making a small C program to resemble the game code breaker or Mastermind.

  • 0

Im making a small C program to resemble the game code breaker or Mastermind. This is my code so far. As of now all it does is generate a “random” code and print the array of the code.. Every time I compile it, it generates the same array of 2,2,6,3. Can anyone help me have a truly random number generator?

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#define CODELENGTH 4
#define NUMSYMBOLS 6
const int LOW = 1;
const int HIGH = 6;




 void genCode (int MasterCode[])
{
int i=0;
int k;
while (i < 4){

MasterCode[i] =rand() %(HIGH-LOW+1)+LOW;
    i++;

}//end while loop.
for ( k = 0 ; k < 4; k++ ) {
    printf( "%d ", MasterCode[ k ] );
}

printf( "\n" );
  }





 void getGuess (int guess[])
 {
int b[ 4 ];
int number = 0;

printf( "Please enter your list of 4 numbers between 1 and 6: " );
int j;
int k;
for ( j = 0 ; j < 4; j++ ) {
    scanf( "%d", &number );
    b[ j ] = number;
}

printf( "Your array has these values: " );

for ( k = 0 ; k < 4; k++ ) {
    printf( "%d ", b[ k ] );
}

printf( "\n" );
}




 int main (int argc, char **argv)
{
int MasterCode[4];
genCode(MasterCode);



}
  • 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-12T07:43:00+00:00Added an answer on June 12, 2026 at 7:43 am

    You need to seed the random number generator before using rand(). This is usually done as:

    srand(time(NULL));
    

    More information available here.

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

Sidebar

Related Questions

I'm making a small program that supposedly get all XML elements that can only
I've been making small scale projects for a while now. I haven't started a
im making a small smiley script , what it does is to change ::1::
I'm making a small online game, where (what do you know) there'll be multiple
I am current making some small JS game in Netbeans and I have started
I am making a small program to draw segments in python using wxpython and
I'm currently making a small program to teach me some new Java, and I'm
I'm making a small program for math (no particular reason, just kind of wanted
How would I go about making a small program that keeps moving the mouse
I'm making a small Python program, which calls the webbrowser module to open a

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.