Generating Random Numbers

This is a discussion on Generating Random Numbers within the C++ Programming forums, part of the General Programming Boards category; #include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main() { srand(time(0)); int x = RAND()%100+1; cout<<x<<endl; return 0; ...

  1. #16
    hacker in training AdamLAN's Avatar
    Join Date
    Sep 2004
    Posts
    56

    Using a random function

    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;

    int main()
    {
    srand(time(0));
    int x = RAND()%100+1;
    cout<<x<<endl;
    return 0;
    }

    //this function returns a random number

  2. #17
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It's "rand" not "RAND"
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #18
    Registered User
    Join Date
    Sep 2004
    Posts
    40
    cheers

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  3. Criteria based random numbers
    By alkisclio in forum C++ Programming
    Replies: 6
    Last Post: 09-14-2006, 12:29 PM
  4. Random Number Generating
    By K.n.i.g.h.t in forum C Programming
    Replies: 9
    Last Post: 01-30-2005, 01:16 PM
  5. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 04:51 PM

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