请问vc里有没有用来产生随机序列的函数,或者谁能帮忙提供一个这方面的算法,谢谢!!
解决方案 »
- windows 窗体背景色变化代码
- 客户端POST到WEB服务器的数据如何加密?
- 奇怪问题,new 了之后delete反而内存泄露更加快了
- 请问要怎么样设置word打印控制的密码和打印份数
- .mix是什么格式?用什么打开?
- 高分求vs.net下载,在线等待。MSN:[email protected]
- 当inlude <global.h>时,出现这个错误什么意思? #error Must specify type of OS ("DOS", "OS2", etc) on C command line!
- 卖血求助)谁能提供有关vb.net开发activex控件然后在客户端ie自动安装的教程
- 为什么我的串口程序必须Sleep一会儿后才能读出正确数据???
- 如何用程序控制关机或重启?
- 高分……………200 200 解决后,马上加分。
- 怎么在工具栏中加入Edit?
/* RAND.C: This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/#include <stdlib.h>
#include <stdio.h>
#include <time.h>void main( void )
{
int i; /* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) ); /* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}
2. 更好的随机数,见 MSDN Platform SDK: Security CryptGenRandom()例
The following code snippet shows the generation of 8 random bytes. These can be used to create cryptographic keys or for any application that uses random numbers.//--------------------------------------------------------------------
// Declare and initialize variables.HCRYPTPROV hCryptProv;
BYTE pbData[16];//--------------------------------------------------------------------
// This code assumes that a cryptographic context has been acquired
// For code details, see "Example C Program: Duplicating a Session
// Key."//--------------------------------------------------------------------
// Generate a random initialization vector.if(CryptGenRandom(
hCryptProv,
8,
pbData))
{
printf("Random sequence generated. \n");
}
else
{
printf("Error during CryptGenRandom.\n");
exit(1);
}
t2=t.GetSecond();
x=t2+rand();
#include "stdlib"
CTimer t=CTimer::GetCurrentTime();
(rand()+t.GetSecond())%最大正整数(注意整数字长)
这是我拷贝的。可能在C语言中用,我没有试,能不能行,我不知道。VC下我改了一下:
CTime t=CTime::GetCurrentTime();
m_random = (rand() + t.GetSecond())%m_range;
m_range为产生随机数的最大值,生成的是0--m_range之间的随机数,这代码我用了的,效果不错,试试吧!