About 9,460,000 results
Open links in new tab
  1. How do I get a specific range of numbers from rand ()?

    Jul 30, 2009 · M + rand() / (RAND_MAX / (N - M + 1) + 1) (Note, by the way, that RAND_MAX is a constant telling you what the fixed range of the C library rand function is. You cannot set …

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

    Oct 28, 2015 · The rand() function returns a pseudo-random integer in the range 0 to RAND_MAX inclusive (i.e., the mathematical range [0, RAND_MAX]). The srand() function sets its argument as …

  3. 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. (from the c++ documentation) The modulus (%) operator gives …

  4. 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 …

  5. c++ - How does modulus and rand () work? - Stack Overflow

    Oct 24, 2013 · A second lesson is that this shows another way in which <random> is easier to use than rand() and manually computing your own distributions. The built-in uniform_int_distribution allows …

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

    printf("%d\n", rand() % 50); 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 …

  7. How does rand() work? Does it have certain tendencies? Is there ...

    Aug 21, 2010 · The actual implementation of the random number generator is left unspecified, so the actual behavior is specific to the implementation. The important thing to remember is that rand does …

  8. How are random numbers generated in C (rand function)?

    May 13, 2021 · 1 rand() in C is commonly implemented as a Linear Congruential Generator (LCG), but there are a lot of random number generators out there. Even though it is a classic way of generating …

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

    srand(rand()); 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 …

  10. Why is the use of rand() considered bad? - Stack Overflow

    Oct 18, 2018 · Usage of rand() is usually frowned upon despite using a seed via srand(). Why would that be the case? What better alternatives are available?