Thread: GNU C Rand()

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    106

    GNU C Rand()

    Hello
    Regarding this source code for a random function:
    https://sourceware.org/git/?p=glibc....nd_r.c;hb=HEAD

    How do you call it to get a random number?
    I have tried:
    Code:
    result = rand_r (seconds) % 1000;
    Where I want a number between 0-100, and seconds could be 0-60.

    Cheers, Brek.
    Last edited by xArt; 02-07-2017 at 04:09 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So what part of a pointer is confusing you?

    > rand_r (unsigned int *seed)

    You're calling it with
    result = rand_r (seconds) % 1000;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rand()
    By ke121885 in forum Linux Programming
    Replies: 1
    Last Post: 10-05-2009, 06:59 AM
  2. rand()
    By kiros88 in forum C Programming
    Replies: 6
    Last Post: 08-31-2009, 05:47 PM
  3. rand()
    By trent in forum C Programming
    Replies: 3
    Last Post: 03-23-2009, 08:32 AM
  4. Difference in Unseeded rand() and seeded rand()
    By relientk_man in forum C++ Programming
    Replies: 5
    Last Post: 11-09-2005, 07:32 AM
  5. rand() ?!?
    By vidal in forum C Programming
    Replies: 4
    Last Post: 01-28-2003, 06:56 PM

Tags for this Thread