zoukankan      html  css  js  c++  java
  • 随机数(random)

    在测试你的程序是否超时时,可以随机生成一组大数据,进行一下测试。

    当然如果你考场上一道题直接读不懂不会做的时候,可以random一下,拼一下RP嘛。2333.

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cstdlib>
    #include<ctime>
    using namespace std;
    int main()
    {
        freopen("xx.in","w",stdout);
        srand((unsigned)time(NULL));
        for(int i=0;i<1000;i++)//随机生成1000个数 
            cout<<rand()%100+1<<endl;//如果这些数有大小限制,可以对其随机生成的数据取模 
        fclose(stdout);
        return 0;
    }
    随机生成

    注意:random()函数只能生成[0,0x7fff]范围内的数.(0x7fff为32767).如果想要生成比起范围更大的数,可以随机生成一些数再乘以10^k使其变为更大的数。

    #include<ctime>
    #include<cstdlib>
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int a[10000];
    int main()
    {
        freopen("xx.in","w",stdout);
        srand((unsigned)time(NULL));
        for(int i=0;i<100;i++)
            a[i]=i+1;
        random_shuffle(a,a+100);//打乱数组中数的顺序,不改变值 
        for(int i=0;i<100;i++)
            cout<<a[i]<<endl;
        fclose(stdout);
        return 0;
     }
    打乱顺序
  • 相关阅读:
    关于头文件
    函数重载和函数模板
    引用和内联函数
    OpenCV中图像处理
    MFC中关于子进程创建和关闭操作
    MFC中的CListControl控件
    MFC中Picture控件显示图像
    MFC CString 和int相互转化
    MFC下拉框
    MFC中关于CListBox控件添加水平滚动条
  • 原文地址:https://www.cnblogs.com/sjymj/p/6025616.html
Copyright © 2011-2022 走看看