Thread: Can this be reduced to two INT variables?

  1. #16
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by laserlight View Post
    I
    Have you read Prelude's old article on using rand()? I found her comments on this use of time to seed rather interesting, i.e., she suggested taking a hash of bytes instead of just passing the result of time, whether as-is or with a cast, on the basis that in theory, even a forced conversion to an integer type is not guaranteed for time_t.
    good read, as rand by rule of thumb is not rand, and that read told me why, I can use that for my program that I use rand a lot in ,I only take them up to an unknown number, and 255, and 360, but I will soon be changing my rand functions to reflect that hash to see what improvements I get. thanks again.
    Last edited by userxbw; 10-19-2017 at 09:01 AM.

  2. #17
    Banned
    Join Date
    Aug 2017
    Posts
    861
    for the student that wants random numbers. just enter the min, max num into the function getRany(int min, int max);
    Code:
    size_t getRany(int min, int max);
    
    int main()
    {
    std::cout << getRany(0, 255) << std::endl;
    }
    
    
    size_t getRany(int min, int max)
    {
        std::random_device seed;
        std::mt19937 gen(seed());
        std::uniform_int_distribution<int> dist(min, max);
        return ( dist(gen) );
    }
    mod:
    oops got over excited and wanted to share, this only works on c++
    Last edited by userxbw; 10-19-2017 at 09:41 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reduced row-echelon form for Bigger Matrix Using C codes
    By SarasMuthu in forum C Programming
    Replies: 10
    Last Post: 08-11-2017, 06:22 AM
  2. Reduced Echelon form program
    By Heartprogrammer in forum C Programming
    Replies: 3
    Last Post: 11-20-2012, 10:40 AM
  3. help with reduced fractions
    By southpark in forum C Programming
    Replies: 1
    Last Post: 10-12-2010, 02:28 AM
  4. how to get a reduced form
    By silent_eyes in forum C++ Programming
    Replies: 3
    Last Post: 02-25-2005, 10:15 PM

Tags for this Thread