improved random seed to be less predictable

This commit is contained in:
unset
2025-01-30 16:09:23 +01:00
parent e55fd0f915
commit c8dce9dc0e
2 changed files with 28 additions and 12 deletions

View File

@@ -0,0 +1,22 @@
name: create package on release
on:
release:
types: [created]
jobs:
build_package_and_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: create deb package
run: dpkg-deb --build ./package
- name: upload release assets
uses: softprops/action-gh-release@v2
with:
tag_name: ${{github.event.release.tag_name}}
files: "${{github.workspace}}/builds/*"

View File

@@ -1,18 +1,12 @@
#include <stdio.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(void) {
srand(time(NULL)); // set the random seed to the system time
char* result = NULL;
if (rand() & (~1) != 0) {
result = "heads";
}
else {
result = "tails";
}
printf("%s\n", result);
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
srand((uint32_t)(ts.tv_nsec ^ ts.tv_sec)); // combine seconds and nanoseconds
printf("%s\n", (rand() & 1) ? "heads" : "tails");
return 0;
}