随机产生一组字符串
我要随机产生一组字符串,要求是第一位是A,第二三位是01~30的一个随机数,第四位是A~E的其中一个字母。假如说我要把A 16 D
组成一个字符串,我该怎么办啊?求程序!谢谢~
2016-09-03 12:06
[此贴子已经被作者于2016-9-3 12:54编辑过]
2016-09-03 12:50
2016-09-03 13:28
2016-09-03 14:52
2016-09-03 15:13
程序代码:#include <stdio.h>
#include <stdlib.h>
int main( void )
{
// srand
while( 1 )
{
char s[5];
int r = int(rand()/(1.0+RAND_MAX) * 150);
sprintf( s, "A%02d%c", r/5%30+1, r%5+'A' );
puts( s );
}
}
2016-09-05 10:01