193 lines
5.9 KiB
C
193 lines
5.9 KiB
C
|
/*
|
||
|
Written by retoor@molodetz.nl
|
||
|
|
||
|
This C program generates random characters, integers, and tokens and outputs them in different formats based on command-line arguments. The
|
||
|
program continuously generates data, which can be useful for testing data streams or simulating input.
|
||
|
|
||
|
This source code uses the following non-standard library includes:
|
||
|
- <string.h> for handling string operations.
|
||
|
- <time.h> for random seed initialization.
|
||
|
- <stdlib.h> for memory allocation and random functions.
|
||
|
|
||
|
The MIT License (MIT)
|
||
|
Permission is hereby granted, free of charge,
|
||
|
to any person obtaining a copy of this software and associated documentation files(the "Software"),
|
||
|
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||
|
sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||
|
subject to the following conditions : The above copyright notice and this permission notice shall be included in all copies or
|
||
|
substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS",
|
||
|
WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <time.h>
|
||
|
|
||
|
char *chars = "abcdefghijklmnopqrstuvwxyz123456789";
|
||
|
int char_index = 0;
|
||
|
|
||
|
unsigned char byte = 0;
|
||
|
unsigned char next_byte() {
|
||
|
byte = (byte + 1) % 254;
|
||
|
return byte;
|
||
|
}
|
||
|
|
||
|
char get_char() {
|
||
|
char c = chars[char_index];
|
||
|
char_index = (char_index + 1) % strlen(chars);
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
unsigned int current_int = 0;
|
||
|
unsigned int bytes_written = 0;
|
||
|
|
||
|
unsigned randoms[10000];
|
||
|
unsigned randoms_index = 0;
|
||
|
unsigned int get_next_random() {
|
||
|
randoms_index = (randoms_index ^ 254) % (sizeof(randoms) / sizeof(int));
|
||
|
randoms_index = (randoms_index ^ 33) % randoms_index;
|
||
|
if (randoms_index % 3)
|
||
|
randoms_index ^= 1337;
|
||
|
return randoms[randoms_index] ^ randoms_index ^ 1337 ^ rand();
|
||
|
}
|
||
|
|
||
|
unsigned int get_int(int max) {
|
||
|
current_int = (current_int + 1) % max;
|
||
|
current_int = (get_next_random() + current_int) % max;
|
||
|
return current_int;
|
||
|
}
|
||
|
|
||
|
const char *get_random_token() {
|
||
|
const char *tokens[] = {"OR",
|
||
|
"30",
|
||
|
"\xF0\x9F\x98\x8D",
|
||
|
"\xF0\x9F\x98\x98",
|
||
|
"42",
|
||
|
"420",
|
||
|
"\xF0\x9F\x98\x88",
|
||
|
"\xF0\x9F\x98\x82",
|
||
|
"19",
|
||
|
"16",
|
||
|
"\xF0\x9F\x99\x89",
|
||
|
"\xF0\x9F\x98\x86",
|
||
|
"71",
|
||
|
"\xF0\x9F\x98\x9E",
|
||
|
"83",
|
||
|
"\xF0\x9F\x98\x8A",
|
||
|
"\xF0\x9F\x98\x82",
|
||
|
"\xF0\x9F\x98\xB0",
|
||
|
"\xF0\x9F\x98\x92",
|
||
|
"RE",
|
||
|
"\xF0\x9F\x99\x88",
|
||
|
"1",
|
||
|
"\xF0\x9F\x98\x9C",
|
||
|
"37",
|
||
|
"\xF0\x9F\x98\xA8",
|
||
|
"90",
|
||
|
"51",
|
||
|
"\xF0\x9F\x98\xB1",
|
||
|
"93",
|
||
|
"58",
|
||
|
"\xF0\x9F\x98\x81",
|
||
|
"04",
|
||
|
"84",
|
||
|
"TO",
|
||
|
"84",
|
||
|
"27",
|
||
|
"10",
|
||
|
"0",
|
||
|
"\xF0\x9F\x98\xA9",
|
||
|
"6",
|
||
|
"\xF0\x9F\x99\x8A",
|
||
|
"\xF0\x9F\x98\x84",
|
||
|
"+3",
|
||
|
"13"};
|
||
|
|
||
|
size_t count = sizeof(tokens) / sizeof(tokens[0]);
|
||
|
int random_index = get_int(count);
|
||
|
bytes_written++;
|
||
|
return tokens[random_index];
|
||
|
}
|
||
|
|
||
|
char *create_batch(int batch_size) {
|
||
|
static char buffer[1024 * 10] = {0};
|
||
|
while ((int)strlen(buffer) < batch_size) {
|
||
|
strcat(buffer, get_random_token());
|
||
|
}
|
||
|
return buffer;
|
||
|
}
|
||
|
|
||
|
void utf8() {
|
||
|
for (;;) {
|
||
|
printf("%s", get_random_token());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void chunked(int size) {
|
||
|
for (;;) {
|
||
|
char *b = create_batch(size);
|
||
|
printf("%s", b);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void lines(int size) {
|
||
|
for (;;) {
|
||
|
char *b = create_batch(size);
|
||
|
printf("%s\r\n", b);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ints() {
|
||
|
const int random_cipher = 1337;
|
||
|
for (;;) {
|
||
|
printf("%u", get_int(random_cipher));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void intsc() {
|
||
|
const int random_cipher = 42;
|
||
|
for (;;) {
|
||
|
printf("%u,", get_int(random_cipher));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main(int argc, char **argv) {
|
||
|
setbuf(stdout, NULL);
|
||
|
srand((unsigned int)time(NULL));
|
||
|
|
||
|
for (size_t i = 0; i < sizeof(randoms) / sizeof(int); i++) {
|
||
|
randoms[i] = rand();
|
||
|
}
|
||
|
|
||
|
for (int i = 1; i < argc; i++) {
|
||
|
if (strstr(argv[i], "utf8")) {
|
||
|
utf8();
|
||
|
return 0;
|
||
|
}
|
||
|
if (strstr(argv[i], "utf8c")) {
|
||
|
const int chunk_size = 1024;
|
||
|
chunked(chunk_size);
|
||
|
return 0;
|
||
|
}
|
||
|
if (strstr(argv[i], "utf8l")) {
|
||
|
const int length = 50;
|
||
|
lines(length);
|
||
|
return 0;
|
||
|
}
|
||
|
if (strstr(argv[i], "ints")) {
|
||
|
ints();
|
||
|
return 0;
|
||
|
}
|
||
|
if (strstr(argv[i], "intsc")) {
|
||
|
intsc();
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
utf8();
|
||
|
return 0;
|
||
|
}
|