[問題] rand()產生的值都一樣
執行之後發現
雖然不同的點有不同的值
但每個點的x y z都是相同的
到底是哪裡出了問題呢
-------------------------------------
#include <iostream>
#include "stdafx.h"
#include <ctime>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int row = 5, xyz = 3;
int dot[row][xyz] = {0};
srand(static_cast<unsigned int>(time(NULL)));
cout << "隨機產生五個點的三維座標" << endl;
for (int i = 0; i < row; i++)
{
cout << "第" << i + 1 << "點 : (";
for (int j = 0; j < xyz; j++)
{
dot[i][j] = rand() - 16383;
cout << dot [i][0] << ",";
}
cout << "\b)\n";
}
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.101.127
推
03/19 20:11, , 1F
03/19 20:11, 1F
→
03/19 20:11, , 2F
03/19 20:11, 2F
推
03/19 20:14, , 3F
03/19 20:14, 3F
→
03/19 20:16, , 4F
03/19 20:16, 4F
→
03/19 20:16, , 5F
03/19 20:16, 5F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章