언리얼에는 RandRage같은 커스텀 랜덤 난수 생성함수가 존재한다
만약 언리얼이아니라면? 사용할수없다
그래서 c++ 보통 랜덤값을 만드는법은 이러하다
1.Google에서 VisualStudio Random을 검색한다
https://learn.microsoft.com/ko-kr/cpp/standard-library/random?view=msvc-170
<random>
자세한 정보:
learn.microsoft.com
2. 랜덤함수를 복사한다
#include <random>
#include <iostream>
using namespace std;
int main()
{
random_device rd; // non-deterministic generator
mt19937 gen(rd()); // to seed mersenne twister.
// replace the call to rd() with a
// constant value to get repeatable
// results.
for (int i = 0; i < 5; ++i) {
cout << gen() << " "; // print the raw output of the generator.
}
cout << endl;
}
만약 범위를 커스텀하게 제어하고싶으면 이와같이 사용하면된다
uniform_int_distribution<> 을 사용하여 dist를 제어할수있다
#include <random>
#include <iostream>
using namespace std;
int main()
{
random_device rd; // non-deterministic generator
mt19937 gen(rd()); // to seed mersenne twister.
uniform_int_distribution<> dist(1,6); // distribute results between 1 and 6 inclusive.
for (int i = 0; i < 5; ++i) {
cout << dist(gen) << " "; // pass the generator to the distribution.
}
cout << endl;
}