Random

This is a discussion on Random within the C++ Programming forums, part of the General Programming Boards category; Whats a good technique for a random number in C++ ?...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    14

    Random

    Whats a good technique for a random number in C++ ?

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    14
    The techniques in the FAQ are probably as good as any.

  3. #3
    Unregistered
    Guest

    rand()

    use rand() function along with randomize()
    (you need to include time.h for this)

    I dont know how effective it is but it is effective..

    The following program shows the 20 random nos.

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

    main()
    {
    int i;
    randomize();

    for(i=0; i<20; i++)
    {
    printf("%d\n", rand());
    }

    }

    hope this helps.
    http://mahurshi.tripod.com/mainframes.htm

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    52
    You can use the "time.h" header file to utilize the system clock to generate random numbers. It's worked for me every time.
    MS VC++ 6.0

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    66
    rand() is not very good for cryptographic applications, and you may need to use a better randomizer (something like L'Ecuyer), but for general purposes it is adequate.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random to int?
    By psyadam in forum C# Programming
    Replies: 7
    Last Post: 07-22-2008, 08:09 PM
  2. Lesson #3 - Math
    By oval in forum C# Programming
    Replies: 2
    Last Post: 04-27-2006, 08:16 AM
  3. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 04:51 PM
  4. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  5. Best way to generate a random double?
    By The V. in forum C Programming
    Replies: 3
    Last Post: 10-16-2001, 04:11 PM

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