生成随机数(C++)

// generate random number

#include <iostream>
#include <iomanip>
#include <cstdlib> // contains function prototype for rand()

using namespace std;
int main()
{
    for (int i = 1; i <= 20; i++) // loop for 20 times
    {
        cout << setw(10) << 1 + rand()%6; // generate numbers between 1 and 6
        if (i%5 == 0) // if have 5 numbers
        {
            cout << endl; // return the nextline

        }

    }


    return 0;
}

posted @ 2019-12-25 00:14  看星星的派大星  阅读(151)  评论(0编辑  收藏  举报