荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: Version (音乐,美的最初与最终), 信区: Program
标 题: Re: 一个随机数的问题
发信站: 荔园晨风BBS站 (Sun May 25 13:55:59 2003), 站内信件
stl里面有random_shuffle()。
#include <algorithm>
int n[9];
for (int i=0; i<9; ++i)
n[i] = i;
random_shuffle(&n[0], &n[8]);
这样就可以将0-8随机地附给数组n了。
Rearranges a sequence of N elements in a range into one of N! possible
arrangements selected at random.
template<class RandomAccessIterator>
void random_shuffle(
RandomAccessIterator _First,
RandomAccessIterator _Last
);
template<class RandomAccessIterator, class RandomNumberGenerator>
void random_shuffle(
RandomAccessIterator _First,
RandomAccessIterator _Last,
RandomNumberGenerator& _Rand
);
Parameters
_First
A random-access iterator addressing the position of the first element in
the range to be rearranged.
_Last
A random-access iterator addressing the position one past the final
element in the range to be rearranged.
_Rand
A special function object called a random number generator.
Remarks
The two versions of the function differ in how they generate random
numbers. The first version uses an internal random number generator
and the second a random number generator function object that is
explicitly passed and can accept a seed value.
【 在 xiaoxin (小新) 的大作中提到: 】
: 你的意思是?...
: 应该怎么用法呢。有一个数组是肯定的,但是我不知道怎样可以达到我说的
: 那样。
: 我想这个问题有点象洗扑克牌,有52张他随机发给每一家。
: 发52次就发完了,52张牌就象一个数组,但是怎么发出去呢?
: 【 在 Version (音乐,美的最初与最终) 的大作中提到: 】
: : 哦。那你用数组然后随机咯。
--
*
* *
* *
no more to say
★ just wish you ★
good luck
※ 修改:·Version 於 May 25 13:56:26 修改本文·[FROM: 192.168.1.50]
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.1.50]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店