生成随机数(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;
}

原文地址:https://www.cnblogs.com/zijidefengge/p/12094368.html