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

  • Home
  • SEARCH
  • 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 8366107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:49:48+00:00 2026-06-09T12:49:48+00:00

My goal is to produce a program which can take a random number from

  • 0

My goal is to produce a program which can take a random number from the user (srand) and then feed it to a random number generator (rand) which then chooses 1000 iterations of a random number between 1 and 10. I then want to output how many of each number was seen (i.e. 7 appears 83 times, etc).

I’m able to printf 1000 numbers between 1 and 10 randomly after taking the initial digit from the user, but can’t figure out how to take this output and feed it to an array which can then be used to break down the information for printing. Can anyone please help?

#include <stdio.h>
#include <stdlib.h>

int rand1(void);
void srand1(unsigned int seed);

int main()

{
    int rand_array[1000];
    int count;
    int start=1;
    int end=10;
    int number_var;
    int ones=0;
    int twos=0;
    int threes=0;
    int fours=0;
    int fives=0;
    int sixes=0;
    int sevens=0;
    int eights=0;
    int nines=0;
    int tens=0;
    int frequency[11];
    int i=0;


    unsigned seed;



    printf("Please enter your choice for seed.\n");
    printf("(between 1-10)");

    while (scanf("%u", &seed) == 1)

    {
        srand1(seed);



        for(i=0; i < 1000; i++)
        {
            rand_array[i]=rand1()%(end-start+1)+start;
            frequency[rand_array[i]]++;
        }

        for(i = 1; i < 11; i++)
        {
            printf("There are %d %d's\n", frequency[i], i);
        }


    }


    return 0;

}





int rand1(void)

{
    static unsigned long int next = 1;

    next = next * 1103515245 + 12345;
    return (unsigned int) (next/65536) % 32768;
}




void srand1(unsigned int seed)

{
    static unsigned long int next = 1;
    next = seed;
}
  • 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-09T12:49:50+00:00Added an answer on June 9, 2026 at 12:49 pm

    You could have an array of size 10 (or 11), type integer, where each slot represents the number of times that number is generated. For example, slot 3 would represent the number of times you generated a 3. So try this:

    //declare array to hold frequencies
    int frequency[11];
    
    //reset all slots to 0
    for(int i = 1; i < 11; i++)
    {
      frequency[i] = 0;
    }
    
    //for each random number, increment the associated slot in the frequency array
    for(int i = 0; i < 1000; i++)
    {
      frequency[rand_array[i]]++;
    }
    
    //print the results
    for(int i = 1; i < 11; i++)
    {
      printf("There are %d %d's\n", frequency[i], i);
    }
    

    Note: I did not really read through most of your existing code, so I’m not sure if you have any other issues.

    Edit: Here is an example of the general idea.

    Say you have some random numbers:

    5, 2, 4, 9, 9, 2, 1, 10
    

    Your frequency array starts at 0s:

    [0,0,0,0,0,0,0,0,0,0]
    

    So now we loop over your random numbers, and increment the associated slot.

    For example, we read the 5, now our frequency array is:

    [0,0,0,0,1,0,0,0,0,0]
    

    Then the 2:

    [0,1,0,0,1,0,0,0,0,0]
    

    Then the 4:

    [0,1,0,1,1,0,0,0,0,0]
    

    Then the 9:

    [0,1,0,1,1,0,0,0,1,0]
    

    Again

    [0,1,0,1,1,0,0,0,2,0] 
    

    At the end:

    [1,2,0,1,1,0,0,0,2,1]
    

    Now we know how many of each number there are! Say we want to know how many 9’s there were, we just look at the 9th slot and we see that there were 2 of them.

    Does this make more sense? This is much better than having 10 separate variables for each number, and then saying “if the number was a 1, increment my 1s variable, if it was a 2, increment the 2s variable”. Plus if you have, say, random numbers between 1 and 100 instead of 1-10, it will be much easier to adapt your code.

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

Sidebar

Related Questions

The goal is to create a program which will effectively let the user create
My goal is to produce a program that will take a file as input
Goal: Produce an Excel document with information from 3 associated models that is similar
My goal is to produce a table with two header rows. The first with
Goal : I wants when I drag image it become fade so we can
Goal: Once i click on the start button on my user interface, i currently
The goal is to produce the following XML with JAXB <foo> <bar>string data</bar> <bar>binary
I am having a problem getting my Pep/8 assembly program to produce the correct
I am writing a program in C++ which involves parsing a lot of text
Given is a row of at most 30 stones which can either be black

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.