怎么编写随机数

4 条评论

  • @ 2024-9-16 20:50:18
    #include<cstdio>
    #include<random>
    int main(){
        std::random_device rd;
        std::mt19937 gen(rd());
        std::uniform_int_distribution<> dis(33, 126);
            printf("%c",dis(gen));
        return 0;
    }
    
    • @ 2024-8-25 11:17:04

      HAHA

      的确“万能”

      • @ 2024-8-25 11:05:46

        e……

        #include <bits/stdc++.h>
        using namespace std;
        int main()
        {
            for (long long i=1;;i++)
            {
            	srand(time(0));
        		long long x=rand();
        		cout << x*i;
            }
            return 0;
        }
        
        • @ 2024-9-15 20:12:48

          设置一次种子之后就不用再设置了呀 awa

          另外 * i 是什么鬼

          这样的随机数是完全可预测的

          也不符合统计学特征

          应该是

          #include <bits/stdc++.h>
          using namespace std;
          
          int main()
          {
              srand(time(0));
              while (1)
              {
                  cout << rand() << endl;
              }
              return 0;
          }
          
      • @ 2024-8-19 13:02:35

        C++

        srand(time(0));
        int x=rand();
        cout<<x;
        

        就懒得写头文件了

      • 1