Thread: random number generation

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    3

    random number generation

    Greetings,
    I have been working on ways to create massive amounts of random numbers from 0 to 7. I have been going nuts with rand(). I want to create a program that will print out sets of 8 random numbers (from 0 - 7) until I tell it to stop. Like well over a billion times. I have studied rand() and srand() and tried many things but the same pattern of 8 numbers keep coming up. Even when I quit the app and restart it, it still has the same pattern of same numbers. A simple example:


    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    int main()
    {
    int x,y;
    srand(time(NULL));

    for(y=0;y<=100;y++);
    {
    for(x=0;x<=7;x++)
    {
    printf("%d ",rand()%8);
    }
    printf("\n");

    }
    }
    Result:
    1 6 7 4 5 2 3 0
    7 4 5 2 3 0 1 6
    5 2 3 0 1 6 7 4, etc

    its the same pattern

    even when I restart the app it is the same numbers with the same patterns
    Im going nuts with this. I even entered random numbers for srand instead of time(NULL) and that did no good. I feel like I am missing something very simple. Can anyone point out what I am doing wrong? I have tried deleting the app and rebuilding. No good. I even rewrote my own rand() and srand() fucntions based on the ASNI C version. No good. Any advice?

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    This is probally a compiler issue. What compiler/os are you using? I have MSVC 6, Borland C Builder 5.0, Borland comand line compiler, and the new G++ and using that code produces no pattern. Also id suggest searching the board for random number generation since this has been talking about a kazillion times.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Counting number from a random file
    By kamisama in forum C Programming
    Replies: 42
    Last Post: 02-22-2005, 05:16 PM
  3. non repeating random number generation?
    By gencor45 in forum C# Programming
    Replies: 1
    Last Post: 02-08-2005, 05:23 PM
  4. random number between negative and positive number
    By anomaly in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2003, 08:40 AM
  5. Random Number Generation
    By drdroid in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 08-02-2003, 03:35 AM