randomm.h (share it)

randomm.h is a C library to generate sequences of pseudo-random numbers by using a seed, which is a positive integer. It can be easly ported to other languages. Its algorithm is used by this online tool and this password generator.

randomm.h:

``` /* randomm.h - a C library to generate pseudo-random numbers */ /* Copyright (C) 2019 Pasquale Frega */ /* All rights reserved */ /* http://pasqualefrega.antiblog.com/ */ /* Released under the simplified BSD license */ /* last edit: 13-Jun-2019 */ /* begin */ /* Maximum random number (try to change only with another odd number) */ #define RAND_MAX 32767 unsigned int SEED = 1; unsigned int TIME = 1; /* Change SEED value */ void srand(unsigned int seed) {  SEED = seed;  TIME = 1; } /* Return a pseudo-random number */ int rand(void) {  SEED += TIME;  if(SEED != RAND_MAX) {   while(SEED < RAND_MAX)    SEED *= SEED + 1;   while(SEED >= RAND_MAX)    SEED -= RAND_MAX;  }  TIME++;  return((int)SEED); } /* end */ ```

test.c:

``` #include <stdio.h> #include "randomm.h" int main(void) {  int _count;  srand(20190613);  printf("10 numbers from 0 to 32767:\n");  for(_count = 0; _count <= 9; _count++)   printf("%d\n", rand());  /* Using % operator changes the range and increases random */  printf("10 numbers from 0 to 32767:\n");  for(_count = 0; _count <= 9; _count++)   printf("%d\n", (rand() % 32768));  printf("10 numbers from 0 to 10:\n");  for(_count = 0; _count <= 9; _count++)   printf("%d\n", (rand() % 11));  printf("10 numbers from 5 to 10:\n");  for(_count = 0; _count <= 9; _count++)   printf("%d\n", ((rand() % 6) + 5));  printf("10 numbers from -5 to 5:\n");  for(_count = 0; _count <= 9; _count++)   printf("%d\n", ((rand() % 11) - 5));  printf("10 numbers from 0.0 to 1.0:\n");  for(_count = 0; _count <= 9; _count++)   printf("%.1f\n", ((rand() % 11) * 0.1));  return(0); } ```

-

randomm.h (and every thing with it) is released under the simplified BSD license: