diff mbox series

[FFmpeg-devel,01/42] tests/fate-run: Ensure that THREADS=random is actually random

Message ID AS8P250MB07444E000D560078B5B4ABF28FFAA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 8d5db120c2572ef81b771b588a81da65cf4b2416
Headers show
Series New API for reference counting and ThreadFrames | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 19, 2023, 7:56 p.m. UTC
From the documentation of GNU awk [1]:
"In most awk implementations, including gawk, rand() starts generating
numbers from the same starting number, or seed, each time you run awk.45
Thus, a program generates the same results each time you run it. The
numbers are random within one awk run but predictable from run to run.
This is convenient for debugging, but if you want a program to do
different things each time it is used, you must change the seed to a
value that is different in each run. To do this, use srand()."

This commit does exactly this.

[1]: https://www.gnu.org/software/gawk/manual/html_node/Numeric-Functions.html#index-rand_0028_0029-function

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 tests/fate-run.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Rheinhardt Sept. 25, 2023, 8:01 p.m. UTC | #1
Andreas Rheinhardt:
> From the documentation of GNU awk [1]:
> "In most awk implementations, including gawk, rand() starts generating
> numbers from the same starting number, or seed, each time you run awk.45
> Thus, a program generates the same results each time you run it. The
> numbers are random within one awk run but predictable from run to run.
> This is convenient for debugging, but if you want a program to do
> different things each time it is used, you must change the seed to a
> value that is different in each run. To do this, use srand()."
> 
> This commit does exactly this.
> 
> [1]: https://www.gnu.org/software/gawk/manual/html_node/Numeric-Functions.html#index-rand_0028_0029-function
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  tests/fate-run.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/fate-run.sh b/tests/fate-run.sh
> index 743d9b3620..8efb1586b8 100755
> --- a/tests/fate-run.sh
> +++ b/tests/fate-run.sh
> @@ -37,7 +37,7 @@ case $threads in
>      random*)
>          threads_max=${threads#random}
>          [ -z "$threads_max" ] && threads_max=16
> -        threads=$(awk "BEGIN { print 1+int(rand() * $threads_max) }" < /dev/null)
> +        threads=$(awk "BEGIN { srand(); print 1+int(rand() * $threads_max) }" < /dev/null)
>          ;;
>  esac
>  

Will apply.

- Andreas
diff mbox series

Patch

diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index 743d9b3620..8efb1586b8 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -37,7 +37,7 @@  case $threads in
     random*)
         threads_max=${threads#random}
         [ -z "$threads_max" ] && threads_max=16
-        threads=$(awk "BEGIN { print 1+int(rand() * $threads_max) }" < /dev/null)
+        threads=$(awk "BEGIN { srand(); print 1+int(rand() * $threads_max) }" < /dev/null)
         ;;
 esac