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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:00:44+00:00 2026-05-22T12:00:44+00:00

#include <stdio.h> double seed=0.579832467; main(ac, av) int ac; char *av[]; { /* declare variables

  • 0
#include <stdio.h>


double seed=0.579832467;

main(ac, av)
int ac;
char *av[];
  {
   /* declare variables */
   float *buf, fac;
   int sf, ne, i;

   /* prototypes? ( shouldn't they be outside the main ) */
   double rnd(), sd;

   /* gets the number of elements from command line */
   ne = atoi(av[1]);

   /* assigns the size of float ( in bytes ) to integer value */
   sf = sizeof(float);

   /* allocates appropriate memory for random number generation */
   buf = (float *)malloc(ne*sf);

   /* type cast, why?? */
   sd = (double)(ne);

   /* no idea what initrnd does */
   initrnd(sd/(sd+187.9753));

   /* checks if memory allocation is successful */
   if (buf == NULL)
     {
      fprintf(stderr, "rndneg: can't allocate %d bytes for buffer\n", ne*sf);
      exit(-1);
     }

   /* fills buffer with random number */
   for (i=0; i<ne; i++)
    {
     buf[i] = (float)(rnd());
    }

   /* writes the buffer, how does it know the file name? */ 
   write(1, buf, ne*sf);
}

/* random number generating function */
double rnd()
{
seed *= 997.0;
seed -= (double)((int)(seed));
return(seed);
}


initrnd(sd)

/* again no idea, why isn't this function void */
double sd;
{
seed = sd;
return(0);
}

This is some code for a PRNG. I am not very experienced with C and some of the things in this code make absolutely no sense to me. I tried to comment to code to track what’s going on. I would appreciate it if some of the things I don’t understand could be cleared up. Especially the declarations of variables and functions with the same name, as well as the initrnd subroutine, that doesn’t seem to be defined in the program or any library I could find on the internet.

Thanks a lot.

  • 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-22T12:00:45+00:00Added an answer on May 22, 2026 at 12:00 pm

    This looks positively ancient.

    A few answers to your questions:

    1. No, prototypes don’t need to be outside functions. It’s most common, perhaps, but not required.
    2. initrnd() just sets the global seed variable to a specific value, that is then used in the PRNG.
    3. The data is written to stdout; which is assumed to be using file descriptor 1. This use of a magical constant is not very pretty, it should be written as stdout (from <stdio.h>).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<stdio.h> double i; int main() { (int)(float)(char) i; printf(%d, sizeof((int)(float)(char)i)); return 0; } The
#include<stdio.h> int main() { double fract=0; int tmp; //scanf(%lf,&fract); fract=0.312; printf(%lf,fract); printf(\n\n); while(fract>0){ fract*=(double)10;
#include<stdio.h> #include<conio.h> main() { int ones,tens,ventoteen,teens, myloop = 0; long num2,cents2,centeens,cents1,thousands,hundreds; double num; do{
#include <stdio.h> #include <limits.h> int main(void){ printf("Type Size Min Max\n----------------------------------------------------------------------\n"); printf("%-20s%-10d%-20ld%-20ld\n", "long", sizeof(long), LONG_MIN,
#include<stdio.h> #include<stdlib.h> #define MAX 1000 struct island{ double left; //gobal double right; } island[MAX];
#include<stdio.h> #include<conio.h> #include<alloc.h> struct node { int data; struct node*link; }; void push(struct node*,int);
#include <stdio.h> #include <iostream> #include <stdlib.h> #include <string.h> using namespace std; void multiplier_matrice_vecteur (char
My code is this // using_a_union.cpp #include <stdio.h> union NumericType { int iValue; long
The project holding the code has all default MSVS2008 settings. Consider the following code
thanks in advance for taking the time to read through my question... /* Binary

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.