整數亂數

Q:產生0~9之間的整數亂數

#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

int main(int argc, char *argv[])
{
srand(time(NULL));
cout << 0 + rand() % (9 - 0 + 1) << endl;
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

這個網誌中的熱門文章

使用memset加快二維陣列初始

TCGS b004: 一個都不能少

UVA Q11614 - Etruscan Warriors Never Play Chess