Re: [PATCH 10/9 v2] test-mergesort: use repeatable random numbers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 08 2021, René Scharfe wrote:

> Am 08.10.21 um 09:23 schrieb Ævar Arnfjörð Bjarmason:
>> Also generally: If you'd like "portable" rand() for a test just shell
>> out to perl. I ran this on various Perl versions (oldest 5.12) on Debian
>> Linux, OSX, Solaris & OpenBSD, all returned the same number for both:
>>
>>     ruby -e 'srand(1); puts rand'; perl -E 'srand(1); say $^V; say rand'
>>
>> Whereas a C program doing the same:
>>
>>     #include <stdio.h>
>>     #include <stdlib.h>
>>
>>     int main(void)
>>     {
>>             srand(1);
>>             printf("rand = %d\n", rand());
>>             return 0;
>>     }
>>
>> Returns different numbers an all, and on OpenBSD the number is different
>> each time, per their well-known non-standard srand()/rand() behavior.
>
> For test shell code that needs only a few random numbers this would
> be fine.
>
> For test-genrandom it would also work, but I don't see any benefit in
> converting it to a scripting language.
>
> Shelling out to a script to avoid a multiplication and a modulo in
> test-mergesort is not interesting, to put it mildly.  A mode that sorts
> input from stdin like the sort subcommand, but returns the operation
> counts, might be useful if you want to test distributions generated by
> a Perl script or other data source of your choice.

Yes, it has zero applicablility here.

It was just an aside/FYI since we were on the topic of the
cross-platformness of rand().

I.e. one might assume that for the general problem of seeding something
randomly cross-platform one had to ship a rand(), but usually at least
perl is there ahead of you, and since it has its own rand()...




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux