如何产生各种随机数
2011-04-21 19:34
204 查看
产生int型随机数
产生随机小数
产生任意范围的数
产生字符串
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<time.h> int main( ) { //freopen( "1.in","r",stdin ); //freopen( "3.out","w",stdout ); srand( time( NULL ) ); int t,n = 10 ; while( n-- ) { printf( "%d\n",rand() ); } return 0; }
产生随机小数
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<time.h> int main( ) { //freopen( "1.in","r",stdin ); //freopen( "3.out","w",stdout ); srand( time( NULL ) ); int t,n = 10 ; while( n-- ) { printf( "%.6lf\n",rand()*1.0 / 100 ); } return 0; }
产生任意范围的数
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<time.h> int main( ) { //freopen( "1.in","r",stdin ); freopen( "3.out","w",stdout ); srand( time( NULL ) ); int t = 99,n = 10 ; while( n-- ) { printf( "%d\n",rand() % t ); } return 0; }
产生字符串
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<time.h> int main( ) { //freopen( "1.in","r",stdin ); freopen( "3.out","w",stdout ); srand( time( NULL ) ); int t = 99,n = 10 ; while( n-- ) { printf( "%c\n",rand() % 26 + 'A' ); } return 0; }
相关文章推荐
- 如何产生各种随机数
- C语言,如何产生随机数(各种转载)
- C语言,如何产生随机数(各种转载)
- C语言,如何产生随机数(各种转载)
- ACM如何产生各种随机数
- 如何产生各种随机数
- C语言,如何产生随机数(各种转载)
- [C]如何产生随机数~
- ORACLE 如何产生一个随机数
- iOS中如何产生随机数
- 通过“中文”两个字来深度剖析各种不同的编码方式,彻底理解乱码是如何产生的?
- 如何在linux中用命令产生一个范围内的随机数?
- 如何高效产生m个n范围内的不重复随机数(m<=n)
- 如何产生一个从x到y的k个随机数 Random(int x,int y ,int k)
- C语言如何产生一个随机数,rand函数的使用
- 给定一个函数rand()能产生0到n-1之间的等概率随机数,问如何产生0到m-1之间等概率的随机数?
- 编程-如何产生随机数
- 编程-如何产生随机数
- MATLAB中如何产生指定范围的随机数
- Java如何产生指定范围内的随机数