ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I need to generate random numbers using /dev/random in C. The numbers should be of type double (64-bit floating point).
The functionality should be equal to linux command "od -An -N8 -t fD /dev/random", but written in C.
Well the code seems to work ... it all looks nice , but just need some opinions if there should be handling of values such as infinities, negative zero or something else
I can't just stretch interval because I'm doing this for homework from numerical analysis ... stretching interval would make it have less possible values, then double type would lose it's efficiency (there was a discussion about this on class).
just need some opinions if there should be handling of values such as infinities, negative zero or something else
I'm not quite sure what you mean by this. Do you mean you want to "generate" +/- infinity, negative 0, etc? If using the above method, since it has range [0.0,1.0) you of course can't do that. I think I recall reading that "-0 == 0" evaluates to true, so you can ignore that "number" (also I think we generally don't ever consider "-0" as a number in analysis anyway). Also, +/- infinity aren't numbers, so you can't generate them as numbers. However, of course, you could use some flag or value, a, so that whenever a is generated, you "pretend" a +/- infinity has occurred.
I can't just stretch interval because I'm doing this for homework from numerical analysis ... stretching interval would make it have less possible values
I think you should be fine if you scale the numbers. You could just multiple the number by a power of ten, 10, 100, 100, etc., depending on how large you want the integral part to be. Say the number 0.1234506789 is generated, you multiply it by 100 to get 12.3450678900... Alternatively, generate a random double to get a fractional number, and add a random integer to it.