[LTP] Broken Fedora build

Yang Xu xuyang2018.jy@cn.fujitsu.com
Thu Oct 22 08:22:39 CEST 2020


Hi Li
> Xiao Yang<yangx.jy@cn.fujitsu.com>  wrote:
>
>>>> I prefer to go replace ftime() by gettimeofday() or clock_gettime()
>>>> way to solve this from root.
>>> +1
>>>
>>> I have seen the hugetlb.c and trace_sched.c code, they all use the
>>> time to generate a random value for ftok or sched_priority. So using
>>> gettimeofday() also looks ok.
>> Hi,
>>
>> It is fine for me to replace ftime(), but I wonder if we can remove
>> fime() and srand()/srandom() directly? :-)
>> It seems unnecessary to set the seed for random number.
>
> That's true, but random() will generate the same number each time.
Agree. If we don't call srandom, repeatly call random binary will give 
same  random num. ie
root@localhost ~]# ./random
random num 1804289383
random num 846930886
random num 1681692777
random num 1714636915
random num 1957747793
random num 424238335
random num 719885386
random num 1649760492
random num 596516649
random num 1189641421
[root@localhost ~]# ./random
random num 1804289383
random num 846930886
random num 1681692777
random num 1714636915
random num 1957747793
random num 424238335
random num 719885386
random num 1649760492
random num 596516649
random num 1189641421
[root@localhost ~]# cat random.c
#include <stdlib.h>
#include <stdio.h>

void main(void)
{
         int num,i;
         for (i=0;i<10;i++) {
                 num =random();
                 printf("random num %d\n", num);
         }
}
[root@localhost ~]#

So keep this maybe better.

Best Regards
Yang Xu
> I slightly tend to keep setting the seed by srandom() to get a different
> randomized number for test variety.
>





More information about the ltp mailing list