Random number in range generation.

This is a discussion on Random number in range generation. within the C Programming forums, part of the General Programming Boards category; Originally Posted by hebali My M and N are negative number: M = -10, N = -400 how does this ...

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by hebali View Post
    My M and N are negative number:
    M = -10, N = -400
    how does this affect the equation?
    Aside from the range being 390, it shouldn't make any difference. In my test-case it works just fine.

    What sequence are you getting?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    For that range, I tried that code generating 1000 numbers instead of just 25 and got 17 repeats... 100 numbers and I got 1 repeat... 25 numbers (run 5 times) and not a single repeat any of those times.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #18
    Registered User
    Join Date
    Feb 2008
    Posts
    84
    Hey,
    I've also been doing some tests on it and I wonder if anyone could speak to something I noticed:
    If I had the program generate only 1 random number, and then I ran that program a few times, there was a higher incidence of repeating than if I had the program generate several random numbers all in one go. Does this make sense given the algorithm?
    Thanks.

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by hebali View Post
    Hey,
    I've also been doing some tests on it and I wonder if anyone could speak to something I noticed:
    If I had the program generate only 1 random number, and then I ran that program a few times, there was a higher incidence of repeating than if I had the program generate several random numbers all in one go. Does this make sense given the algorithm?
    Thanks.
    Sure, it makes sense given that the change in the original seed given to srand() is "similar", which leads to a more likely incidence of the same number [if time is measured in seconds, then two calls within the same second will give the same seed -> same random number].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #20
    Registered User
    Join Date
    Feb 2008
    Posts
    84
    gotcha. makes sense. thanks.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random number generation
    By parisha in forum C Programming
    Replies: 9
    Last Post: 12-17-2008, 10:00 AM
  2. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 04:51 PM
  3. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  4. Random number generation
    By Lisa Mowbray in forum C++ Programming
    Replies: 4
    Last Post: 04-30-2002, 12:22 PM
  5. Random number generation
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 04-16-2002, 06:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21