跳到正文

算法·理论

随机数插件

MixxxxTion约 2 分钟
原文

这是 2026年8月4日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年8月4日
收录
2026年8月4日
更新
2026年11月6日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1

一个自己写的生成随机数的代码,版本号在代码中备注

C++
//0.0.0
#include<bits/stdc++.h>
#define int long long
using namespace std;
int Random_List[10000005],Point_Number_Pos,Random_List_Size;
int Randomly_Change_Number(int x){//It's useful.
	x^=0x15e2cc06f611bce5ll;
	x=(x>>31)^x;
	x+=0xc516a6837caaf61bll;
	x=(x^(x>>26))*0x16ab06dede20b9125ll;
	return (x-0x3949c48766d508bfll)^x;
}
void Make_Good_Randomly_Number(int seed,int size,int a[]){//We need a good seed.It can make some good random number.
	a[0]=seed;
	for(int i=1;i<=size;++i){
		a[i]=Randomly_Change_Number(a[i-1]);
	}
}
void init_rand(int len,int seed=1){//It can make a randomly array.
	Make_Good_Randomly_Number(seed,len,Random_List);
	Random_List_Size=len;
	Point_Number_Pos=0;
}
int get_rand(int l,int r,int Random_List[]=Random_List){//Get a randomly number.
	if(Point_Number_Pos==Random_List_Size)Point_Number_Pos=0;
	int x=Random_List[++Point_Number_Pos],mod=r-l+1;
	x=(x%mod+mod)%mod;
	return x+l;
}
signed main(){//sample
	init_rand(100,time(NULL));
	for(int i=1;i<=20;i++){
		cout<<get_rand(1,10000)<<" ";
	}
	return 0;
}