1# $NetBSD: varmod-order-shuffle.mk,v 1.8 2023/02/26 06:08:06 rillig Exp $ 2# 3# Tests for the :Ox variable modifier, which returns the words of the 4# variable, shuffled. 5# 6# The variable modifier :Ox is available since 2005-06-01. 7# 8# As of 2020-08-16, make uses random(3) seeded by the current time in seconds. 9# This makes the random numbers completely predictable since the only other 10# part of make that uses random numbers is the 'randomize-targets' mode, which 11# is off by default. 12# 13# Tags: probabilistic 14 15WORDS= one two three four five six seven eight nine ten 16 17# Note that 1 in every 10! trials two independently generated 18# randomized orderings will be the same. The test framework doesn't 19# support checking probabilistic output, so we accept that each of the 20# 3 :Ox tests will incorrectly fail with probability 2.756E-7, which 21# lets the whole test fail once in 1.209.600 runs, on average. 22 23# Create two shuffles using the := assignment operator. 24shuffled1:= ${WORDS:Ox} 25shuffled2:= ${WORDS:Ox} 26.if ${shuffled1} == ${shuffled2} 27. error ${shuffled1} == ${shuffled2} 28.endif 29 30# Sorting the list before shuffling it has no effect. 31shuffled1:= ${WORDS:O:Ox} 32shuffled2:= ${WORDS:O:Ox} 33.if ${shuffled1} == ${shuffled2} 34. error ${shuffled1} == ${shuffled2} 35.endif 36 37# Sorting after shuffling must produce the original numbers. 38sorted:= ${WORDS:Ox:O} 39.if ${sorted} != ${WORDS:O} 40. error ${sorted} != ${WORDS:O} 41.endif 42 43all: 44