Like Tree1Likes

How to generate random number without repetition?

This is a discussion on How to generate random number without repetition? within the C Programming forums, part of the General Programming Boards category; Originally Posted by memcpy Also note that the error might be because every time you run calloc() in the loop, ...

  1. #31
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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?

    Code:
    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 10: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

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 11-02-2011, 10: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, 09:57 AM
  4. Replies: 11
    Last Post: 07-16-2002, 12:39 PM
  5. Ask about generate Random number
    By ooosawaddee3 in forum C Programming
    Replies: 2
    Last Post: 07-01-2002, 05:30 AM

Tags for this Thread


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