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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:06:38+00:00 2026-06-09T02:06:38+00:00

Still having trouble generating random seeds. Here’s my code: #include <stdio.h> #include <stdlib.h> #include

  • 0

Still having trouble generating random seeds. Here’s my code:

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

double dev_random_seed(){
  double randval;
  FILE* f;

  f = fopen("/dev/random", "r");
  if(f == NULL){
    fprintf(stderr, "WARNING: Failed to open /dev/random. Random seed defaults to 1. \n");
    return 1;
  }

  fread(&randval, sizeof(double), 1, f);
  fclose(f);
  return randval;
}

int main(int argc, char** argv){
  double arse = dev_random_seed();

  printf("errno: %i\n",errno);
}

The output of which is:

errno: 22

which is EINVAL. Can’t spot the mistake , I suck at c.

  • 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-09T02:06:39+00:00Added an answer on June 9, 2026 at 2:06 am

    Don’t check errno unless you have an error.
    It may be that a library sets a value of errno in advance because it represents a cause that a later part won’t know IF the later part has an error (sorry that could be clearer)

    See https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=6619179

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

Sidebar

Related Questions

I'm still having trouble with the same application as mentioned here Delphi CopyMemory vs
I'm still having trouble understanding how to copy structs that include char* fields\other struct
I am still having trouble understanding what interfaces are good for. I read a
I have seen the other posts but I am still having trouble. Below is
There are no shortage of questions on this topic, but I'm still having trouble.
I'm starting to understand git but I'm still having some trouble with the abstraction.
I'm having trouble getting my dropdown menu to still work after I empty it's
I'm having trouble finding info right now; it might still be too early. But
i'm still transitioning from as2 to as3, i'm having trouble with parsing XML data
Still having trouble with this language. Ok, let's say I have two objects. The

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.