Thread: How to generate random number without repetition?

  1. #31
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    Quote Originally Posted by memcpy View Post
    Also note that the error might be because every time you run calloc() in the loop, you're allocating 12,000 bytes. Run this 1500 times, and you'll be allocating 18,000,000 bytes. Your OS probably doesn't allow a single program to take up this much memory.
    Oh, it will. But unfortunately the fun doesn't stop at just 1500 times...

    Quote Originally Posted by Suntang
    allocated row 11597
    SUNTANG! THINK! Why is that happening? How many rows did you code that loop to allocate?

    for(r=0; columns; r++)
    Either this is a typo you still haven't spotted, or there is something about for() loops you have misunderstood. Either way, there is a major major problem right there. Read posts #23 and #26 carefullly again. In #23, I thought that was not the "real code" but it turned out that it was, which is why I said in #26 "so you do have an infinite loop in there". I thought that would be obvious enough...sorry.
    Last edited by MK27; 03-19-2012 at 09:28 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 11-02-2011, 09:53 AM
  2. how to generate a random number in c?
    By blogchama in forum C Programming
    Replies: 2
    Last Post: 01-20-2011, 10:39 AM
  3. Generate Random Number
    By peacealida in forum C++ Programming
    Replies: 10
    Last Post: 04-06-2008, 08:57 AM
  4. Replies: 11
    Last Post: 07-16-2002, 11:39 AM
  5. Ask about generate Random number
    By ooosawaddee3 in forum C Programming
    Replies: 2
    Last Post: 07-01-2002, 04:30 AM

Tags for this Thread