random double numbers

This is a discussion on random double numbers within the C Programming forums, part of the General Programming Boards category; Hi Which function can I use to make random numbers in double. Normally the rand(), randomize and random is randomizing ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    64

    random double numbers

    Hi

    Which function can I use to make random numbers in double.
    Normally the rand(), randomize and random is randomizing numbers in int.

    How can I get ex. 10 double numbers...

    Tx for help

    Gugge
    !G!

  2. #2
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    double drand ( double low, double high )
    {
        return ( (double)rand() * ( high - low ) ) / (double)RAND_MAX + low;
    }
    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    Prelude,

    Is RAND_MAX valid for all platforms? The reason I'm asking is that I can't seem to use it on my HP-UNIX account at school. I am I doing something wrong. I can use INT_MAX, LONG_MAX, etc.
    'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Is RAND_MAX valid for all platforms?
    RAND_MAX is a macro defined in stdlib.h, it is a standard feature according to ISO C89 and C99. If you aren't including stdlib.h then the compiler probably won't let you use RAND_MAX, but it should also complain about rand() being undefined as well.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    I am definatley including stdlib.h, and rand() has no flags or warnings. I have to use this macro in my makefile though:

    CFLAGS = -Ae +DAportable

    Maybe this is part of it. I know the system is pretty old. Any ideas?
    'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    It may be pre-ANSI and not have it, check the documentation to see if there is an alternative. I'm also not familiar with the -Ae flag, what does it do exactly?

    -Prelude
    My best code is written with the delete key.

  8. #8
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    I'm clueless as to what the -Ae flag does. I'm guessing it is a command for the linker to use some environment variable to locate some important shared libraries. I will have to ask around.
    'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 09:38 PM
  2. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 09:54 PM
  3. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM
  4. random numbers
    By ballmonkey in forum C++ Programming
    Replies: 3
    Last Post: 01-18-2005, 02:16 PM
  5. standard deviation on random numbers?
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 05-13-2002, 04:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21