You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1021 B
30 lines
1021 B
2 years ago
|
### mt19937 是啥玩意?
|
||
|
|
||
|
**懵逼树上懵逼果,懵逼树下只有我**
|
||
|
|
||
|
**简介**
|
||
|
$mt$是指$maxint$(整型$int$最大值的缩写)
|
||
|
$19937$是指$2^{19937}-1$
|
||
|
|
||
|
$mt19937$是$c++11$新特性,它是一种随机数算法,用法与$rand()$函数类似,但是$mt19937$具有速度快,周期长的特点(所谓周期长应该是指$19937$所代表的意思吧),$rand()$在$windows$下生成的数据范围为$0-32726$,此时的$mt19937$所生成的数据范围大概为
|
||
|
$(-maxint,+maxint)$($maxint$整型$int$最大值的缩写)
|
||
|
|
||
|
**总结**
|
||
|
这玩意要想生成特别多的随机数,碰撞小,就使这个,能顶到$int$的整个区间不重复。
|
||
|
如果不使,只能有$32726$个随机数。
|
||
|
|
||
|
还是使上好,要不,给你多点数据,就完蛋了,树就不平衡了,就$O(N)$了!
|
||
|
|
||
|
```c++
|
||
|
#include <bits/stdc++.h>
|
||
|
using namespace std;
|
||
|
|
||
|
//更牛B的随机数生成器
|
||
|
mt19937 rnd(time(0));
|
||
|
|
||
|
int main() {
|
||
|
printf("%lld\n", rnd());
|
||
|
return 0;
|
||
|
}
|
||
|
```
|