- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int z,m;
- cout << "輸入一個種子亂數的最小值:";
- cin >> z;
- cout << "輸入一個種子亂數的最大值:";
- cin >> m;
- cout << "公式為:(rand() % (" << m << "-" << z << ") + 1)"<< endl;
- for (int b = 1; b <= 10; b++)
- {
- int a = (rand()% (m - b + 1) + m);
- cout << "第" << b <<"個亂數:" << a << endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |