diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c5d8c36..327fc704 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -87,7 +87,10 @@ jobs: - name: Generate Entropy shell: bash run: | - tools/entropy.sh + # Get the first 8 characters of the SHA (enough for a decent seed) + SHA_PREFIX=$(echo "${{ github.sha }}" | cut -c 1-8) + + tools/entropy.sh $((16#$SHA_PREFIX + ${{ matrix.instance }})) - name: Build shell: cmd diff --git a/tools/entropy.sh b/tools/entropy.sh index 397123c2..11909999 100644 --- a/tools/entropy.sh +++ b/tools/entropy.sh @@ -3,29 +3,65 @@ # Output file OUTPUT_FILE="entropy.h" -# Function to generate a random CamelCase string of given length +# Function to generate a CamelCase string of given length generate_name() { - cat /dev/urandom | tr -dc 'a-z' | fold -w "$1" | head -n 1 | sed -E 's/(^|_)([a-z])/\U\2/g' + local seed="$1" + local length="$2" + local char_count=0 + local random_bytes="" + + while [ "$char_count" -lt "$length" ]; do + random_bytes+=$(od -vAn -N4 -tu4 < /dev/urandom | tr -d '[:space:]') + char_count=$((char_count + 1)) + done + + # Use the provided seed for the random number generation. Crucially, re-seed bash's + # RANDOM for each name. + RANDOM="$seed" + + local result="" + for ((i=0; i" + exit 1 +fi + +SEED="$1" +# Initialize the random number generator with the seed +RANDOM="$SEED" + # Generate a random number of classes (between 1 and 10) NUM_CLASSES=$((RANDOM % 10 + 1)) > "$OUTPUT_FILE" # Clear or create the output file +echo "// Seed: $SEED" > "$OUTPUT_FILE" +echo >> "$OUTPUT_FILE" + for ((i=0; i> "$OUTPUT_FILE" - + # Generate a random number of methods (between 1 and 10) NUM_METHODS=$((RANDOM % 10 + 1)) for ((j=0; j> "$OUTPUT_FILE" + METHOD_NAME="Function$(generate_name "$((SEED + i * 100 + j))" 8)" + echo -e "\tinline void $METHOD_NAME() {}" >> "$OUTPUT_FILE" done - + echo "};" >> "$OUTPUT_FILE" - echo >> "$OUTPUT_FILE" # Add an empty line for readability + echo >> "$OUTPUT_FILE" done echo "Generated $NUM_CLASSES classes in $OUTPUT_FILE"