c - Is it possible to peek at the next rand value -


assuming generator has been seeded, possible peek @ next random value without changing it?

i.e. given:

#include <stdlib.h>  int r; r = rand(); // 99 r = rand(); // 80 

is possible

#include <stdlib.h>  int r; r = peekatrand(); // give 99 r = rand(); // still gives 99  r = peekatrand(); // give 80 r = rand(); // still gives 80 

furthermore, can extended peeking @ next n numbers?

you can implement peekatrand follows:

int peekatrand() {     int r,s;     s = rand();     srand(s);     r = rand();     srand(s);     return r; } 

to make "worthy", call srand((unsigned int)time(null)) @ beginning of program.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -