About 51 results
Open links in new tab
  1. rand() function in c++ - Stack Overflow

    Sep 27, 2011 · The c++ rand () function gives you a number from 0 to RAND_MAX (a constant defined in <cstdlib>), which is at least 32767. () The modulus (%) operator gives the remainder after dividing. …

  2. c - How does srand relate to rand function? - Stack Overflow

    Where is the connection between rand and srand? What I mean or expect is I assume rand () will get some parameter from srand () so it knows to generate different numbers each time. I assume it …

  3. c - What does `rand () % 2` mean? - Stack Overflow

    Jun 12, 2023 · The rand() % 2 is a way of generating a pseudo-random number that's either 0 or 1. The rand() function generates a pseudo-random integer. When you take the modulus of that integer by 2 …

  4. What's the Right Way to use the rand () Function in C++?

    This basically just did the same as the program did in the first place but outputted a different set of numbers (which makes sense since the first number generated by rand () is always 41.) The only …

  5. rand() returns the same number each time the program is run

    Every time you call rand () it takes the seed and/or the last random number (s) generated (the C standard doesn't specify the algorithm used, though C++11 has facilities for specifying some popular …

  6. c - rand () seeding with time () problem - Stack Overflow

    Sep 12, 2010 · I'm having difficulty figuring out how to use rand() and seeding it with time() using Xcode. I want to generate random decimal numbers between 0 and 1. The code gives me seemingly random …

  7. What difference between rand () and random () functions?

    9 Functions rand() and random() are either defined by POSIX since at least POSIX.1-2001 (and randomize() is not standardized). On older rand() implementations, and on current implementations …

  8. How do I get a specific range of numbers from rand ()?

    Jul 30, 2009 · Here is my answer there, which contains the definition for my int utils_rand(int min, int max) func, which returns a random number using rand() which is in the specific range from min to …

  9. How does rand() work in C? - Stack Overflow

    Oct 28, 2015 · Finally, rand() % 50 means "call rand(), divide the result by 50, and then take the remainder". (The % is the modulus operator, which means you want the remainder.) For example, if …

  10. How to generate a random int in C? - Stack Overflow

    Aug 4, 2015 · 10 STL doesn't exist for C. You have to call rand, or better yet, random. These are declared in the standard library header stdlib.h. rand is POSIX, random is a BSD spec function. The …