About 22,700,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 …

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

    Aug 4, 2015 · Many implementations of rand() cycle through a short list of numbers, and the low bits have shorter cycles. The way that some programs call rand() is awful, and calculating a …

  4. 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 (%) …

  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 …

  6. Generate a value between 0.0 and 1.0 using rand () - Stack Overflow

    The OP's reasoning for trying it was wrong, but had this been necessary, the UB could've been avoided by adding 1.0 instead of 1, which would coerce RAND_MAX to double type and so …

  7. How to get current seed from C++ rand ()? - Stack Overflow

    The Posix function rand_r() gives you control of the seed. The C++11 library includes a random number library based on sequence-generating "engines"; these engines are copyable, and …

  8. How do I generate a random number for each row in a T-SQL select?

    I need a different random number for each row in my table. The following seemingly obvious code uses the same random value for each row. SELECT table_name, RAND() magic_number …

  9. rand () Function to give a 32-bit random unsigned int

    Nov 16, 2021 · You can fix the overlap problem by reducing the rand result to 15 bits before applying |. Or, if you know the rand implementation being used returns only 15-bit numbers …

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