Thread: Fix Please

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Usually, it means you give the computer a start number, then it applies an algorithm on that number to produce "random" numbers.
    Of course, there are "random" generators and not-so-random generators (not-so-random generators may produce the exact same sequence of numbers from the same seed).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Well actually, you can get a pseudorandom number algorithmically by multiplying a seed with a constant and taking the mod of another constant. I'll show you one:
    Code:
    int seed=1;
    
    void LCGseed (unsigned int _seed)
    {
       int i, h=1;
       unsigned char *p=&_seed;
       for (i=0; i < sizeof _seed; h++) {
          h = h>>24 * h<<4 ^ p[i];
       }
       seed=h;
    }
    
    int LCGrand (void)
    {
       return seed*=16807UL &#37; 2147483647UL;
    }
    The algorithm, when called several times, naturally produces a series called a period. Large periods are good, but more important is the factor of unpredictability. We shouldn't rely on the default seed because that would make the generator more predictable and the result very deterministic. The seed is actually the last number the generator returned. If you're using the generator for the first time, it would be a good idea to set the seed somewhere in the period to start off from other than the default value, using a unique source, like the time.

    The example is actually a great deal similar to the rand/srand generator provided by C++, and that's not a very good one. But it's a place to start. You can learn more about PRNGs on the web.
    Last edited by whiteflags; 06-19-2008 at 12:35 PM.

  3. #18
    Registered User
    Join Date
    May 2008
    Posts
    81
    Quote Originally Posted by Nestor View Post
    Listem men, i started programing yesterday....well today 1 am, i havn't gotten as far as a random numbers generator:P but if you are bored you can explain how it can be a random number generator if the computer can't think for itself?
    since you asked...

    http://cboard.cprogramming.com/showthread.php?t=103889

    for through understanding, read till the last page.
    Last edited by shawnt; 06-20-2008 at 12:58 PM. Reason: fixed link

  4. #19
    Registered User
    Join Date
    Jun 2008
    Posts
    25
    That link doesn't work

  5. #20
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It's got an extra http// in it by mistake. Delete that in the address bar and you can follow it.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #21
    Registered User
    Join Date
    Jun 2008
    Posts
    266

    go back

    Go back to tutorials. In my opinion Cprogramming tutorials suck so find a better online tutorial, buy a book, or just stop posting such stupid threads

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    And you'd better learn to control that attitude of yours, because frankly, it sucks.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Registered User
    Join Date
    Jun 2008
    Posts
    25
    Me? Was that to me?

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, to lruc.
    Nothing wrong with you, Nestor. Don't worry.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. compiling my code, i can't fix error
    By howru in forum C Programming
    Replies: 2
    Last Post: 04-22-2008, 03:38 AM
  3. Drag and Drop code (please help me fix)
    By John_L in forum C# Programming
    Replies: 1
    Last Post: 11-17-2007, 06:11 PM
  4. C++ code need help to fix
    By McReal in forum C++ Programming
    Replies: 9
    Last Post: 05-12-2007, 02:48 PM
  5. Help me fix my mess!!!!
    By Starr in forum C++ Programming
    Replies: 35
    Last Post: 02-01-2006, 03:40 PM