Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

How do I make this faster?

Name: Anonymous 2019-09-10 17:01

#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int myrand(int min, int max) {
int new_value;
static int previous_value;

if(min > max) return 1;

do {
srand(time(NULL));
new_value = rand() % (max - min);
} while(new_value == previous_value);

previous_value = new_value;
return new_value;
}

int main() {
for(register char c = 0; c < 5; c++) {
printf("%c\t", myrand(33, 126));
}

putchar('\n');
return 0;
}

Name: Anonymous 2019-09-11 22:26

with Ada.Numerics.Discrete_Random;
with Ada.Text_IO; use Ada.Text_IO;
procedure Random is
subtype Printable_Character is Character range Character'Val(33) .. Character'Val(126);
package Random_Printable_Character is new Ada.Numerics.Discrete_Random(Printable_Character);
use Random_Printable_Character;
G : Generator;
Current, Previous : Character := Character'Val(0);
function Unique return Character is
begin
loop
Current := Random(G);
exit when Current /= Previous;
end loop;
Previous := Current;
return Current;
end Unique;
begin
Reset(G);
for I in 1..5 loop
Put(Unique);
end loop;
New_Line;
end Random;

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List