• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include "test.h"
19 
20 /**
21  * @tc.name      : srand_0100
22  * @tc.desc      : Test the srand function to set the random number seed
23  * @tc.level     : Level 0
24  */
srand_0100(void)25 void srand_0100(void)
26 {
27     int a[10] = {0};
28     int b[10] = {0};
29     srand(10);
30     for (int i = 0; i < 10; i++) {
31         a[i] = rand();
32     }
33     srand(10);
34     for (int i = 0; i < 10; i++) {
35         b[i] = rand();
36     }
37     for (int i = 0; i < 10; i++) {
38         if (a[i] != b[i]) {
39             t_error("%s srand rand in %d is %d , %d \n", __func__, i, a[i], b[i]);
40         }
41     }
42 }
43 
44 /**
45  * @tc.name      : srand_0200
46  * @tc.desc      : Change the random number seed
47  * @tc.level     : Level 1
48  */
srand_0200(void)49 void srand_0200(void)
50 {
51     int a = 0;
52     int b = 0;
53     srand(10);
54     a = rand();
55     srand(500);
56     b = rand();
57     if (a == b) {
58         t_error("%s srand get rand is %d , %d \n", __func__, a, b);
59     }
60 }
61 
main(int argc,char * argv[])62 int main(int argc, char *argv[])
63 {
64     srand_0100();
65     srand_0200();
66     return t_status;
67 }