|
发表于 2022-10-18 21:36:55
|
显示全部楼层
本帖最后由 jackz007 于 2022-10-18 21:39 编辑
不会呀,试试这个代码:
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <conio.h>
- int main(void)
- {
- int i ;
- time_t t ;
- srand((unsigned) time(& t)) ;
- for(i = 0 ; i < 20 ; i ++) printf("%d , %d\n" , rand() % 6 + 1 , rand() % 6 + 1) ;
- }
复制代码
编译、运行实况:
- D:\[00.Exerciese.2022]\C>g++ -o x x.c
- D:\[00.Exerciese.2022]\C>x
- 5 , 2
- 6 , 4
- 5 , 2
- 5 , 6
- 2 , 4
- 3 , 2
- 4 , 6
- 6 , 5
- 2 , 1
- 4 , 6
- 3 , 4
- 1 , 6
- 6 , 6
- 6 , 5
- 4 , 3
- 4 , 2
- 4 , 3
- 2 , 3
- 1 , 4
- 5 , 5
- D:\[00.Exerciese.2022]\C>
复制代码
连续两次调用产生的两个随机数相等的概率并不高。 |
|