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