首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

哪位高手来帮个忙,C语言从一个int数组里面随机一个数咋写

2012-03-21 
谁来帮个忙,C语言从一个int数组里面随机一个数咋写我知道python的很简单random.choice(list)[解决办法]C/C

谁来帮个忙,C语言从一个int数组里面随机一个数咋写
我知道
python的很简单
random.choice(list)


[解决办法]

C/C++ code
int i = 0;srandom(seed);//设一个随机种子i = list[random()%n]; // n = 数组长度
[解决办法]
c++ 也很简单!

C/C++ code
#include <iostream>#include <Windows.h>using namespace std;int main(){    int a[]={1,2,3,4,5};    cout<<a[GetTickCount()%sizeof(a)/sizeof(a[0])];    return 0;} 

热点排行