0
已解决
蒋宇韩
中级守护
中级守护
我们都知道
rand()函数是伪随机数,并不是完全随机,于是,我经过1个小时的琢磨,搞出来了
一种随机数,非常的杂乱无章,上代码:
#include<iostream>
#include<cstdlib>
#include<ctime>
#define MAX 12+93541131%2
using namespace std;
clock_t start,finish;
int n,m=1000//m是随机次数 n是范围;
int gettime(){
finish=clock();
return finish-start/CLOCKS_PER_SEC;
}
int rand_(int max){
unsigned int s=gettime()/(2^4)+(6^13)%(MAX^(212^123)+(632^562));
unsigned int a=(s^max),b=(a^max),nUll=(12>>4)+((s-2)<<2)+(int)(finish-start);
unsigned int A=(b^max)+nUll,B=(A^max)-nUll;
unsigned int aa=(B^max)*nUll,bb=(aa^max)/nUll;
unsigned int AA=(bb^max)%nUll,BB=(AA^max)^nUll;
finish=clock()*24/a+b%BB;
start=clock()%645*123+A*b;
return ((s+a+b+A+B)+(finish^start)+(gettime()^(finish+start)))%max;
}
int main(){
cin>>n;
while(m--){
start=clock();
cout<<rand_(n)+1<<endl;
}
return 0;
}
运行结果:
emm,虽然不是完全随机,但是比rand()要随机一点
蒋宇韩在2022-09-12 12:17:24追加了内容
不过这种随机数不太可能生成小的数字(除非范围很小)
蒋宇韩在2022-09-25 20:33:25追加了内容
更新了!!!
#include<iostream>
#include<ctime>
#define MAX 12+93541131%2
using namespace std;
clock_t start,finish;
int n,m=1000;//m是随机次数 n是范围;
int gettime(){
finish=clock();
return finish-start/CLOCKS_PER_SEC;
}
int rand_(int max){
unsigned int s=gettime()/(2^4)+(6^13)%(MAX^(212^123)+(632^562));
unsigned int a=(s^max),b=(a^max),nUll=(12>>4)+((s-2)<<2)+(int)(finish-start);
unsigned int A=(b^max)+nUll,B=(A^max)-nUll;
unsigned int aa=(B^max)*nUll,bb=(aa^max)/nUll;
unsigned int AA=(bb^max)%nUll,BB=(AA^max)^nUll;
s+=((s>>2)+(s<<3)*2&124142141);finish>>=2;
s+=((s>>2)+(s<<3)*2&121414121);s^=28423;
finish=clock()*24/a+b%BB+21121;s^=173617;
start=clock()%645*123+A*b+27932;start>>=2;
s-=12423425;s^=1232132132;s^=272131;s+=121;
finish+=0x3ff;finish-=0x3fff*2.1;s%=127312;
start+=0x3fff;start-=0x3fff*4;s^=213;s*=12;
const int MIN=101212;s-=2131;s^=123131;s%=181232123;
s^=MIN;s^=MIN-123;s^=1312313;s^=37112;s-=271371;s%=1231;
finish%=123223;start%=213233;start%=2133;finish%=212733;
return ((s+a+b+A+B)+(finish^start)+(gettime()^(finish+start)))%max;
}
int main(){
cin>>n;
while(m--){
start=clock();
cout<<rand_(n)+1<<endl;
}
return 0;
}
0
0
0
0
0
孟昭旭
初级光能
初级光能
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
int n;
int main(){
cin>>n;
srand(time(0));
for (int i=1;i<=rand();i++){
srand(rand()%100000);
}
for (int i=1;i<=rand();i++){
srand((rand()+time(0))%100000);
}
for (int i=1;i<=n;i++){
cout<<rand()<<" ";
srand((rand()+time(0))%100000);
Sleep((rand()%2000/4)+(rand()%2000/4));
}
return 0;
}
//RAND()??
简简单单才是真(虽然也是伪随机)
0
0
0
0