Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Linear Algebra and the C Language/a00d

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

__NOTOC__ Install this file in your working directory. /* ------------------------------------ */ /* Save as : z_r.h */ /* ------------------------------------ */ /* ------------------------------------ Call : time_t t; int i; srand(time(&t)); i = r_I(9); ------------------------------------ */ /* ------------------------------------ positive and negative numbers without zero ------------------------------------ */ int r_I( int maxI) { int x; x = (rand() % maxI) + 1; /* + 1 : not zero */ x *= pow(-1,rand()); return(x); } /* ------------------------------------ positive numbers without zero ------------------------------------ */ int rp_I( int maxI) { return((rand() % maxI) + 1); /* + 1 : not zero */ } /* ------------------------------------ positive and negative numbers with zero ------------------------------------ */ int r0_I( int maxI) { int x; x = rand()%maxI; if(x) x*=pow(-1,rand()); return(x); } /* ------------------------------------ positive numbers with zero ------------------------------------ */ int rp0_I( int maxI) { return(rand() % maxI); } /* ------------------------------------ */ /* ------------------------------------ */ /* ------------------------------------ */ /* ------------------------------------ positive and negative floating point number without zero e= 1E-0 -> 1234 e = 1E-1 -> 123.4 e = 1E-2 -> 12.34 e = 1E-3 -> 1.234 ------------------------------------ */ double r_E( int maxI, double e) { double x; x = (rand() % maxI) + 1 ; /* + 1 : not zero */ x *= pow(-1,rand()) * e; return(x); } /* ------------------------------------ */ /* ------------------------------------ positive and negative floating point number with zero e= 1E-0 -> 1234 e = 1E-1 -> 123.4 e = 1E-2 -> 12.34 e = 1E-3 -> 1.234 ------------------------------------ */ double r0_E( int maxI, double e) { double x; x = (rand() % maxI); x *= pow(-1,rand()) * e; return(x); } /* ------------------------------------ */ /* ------------------------------------ positive floating point number without zero e= 1E-0 -> 1234 e = 1E-1 -> 123.4 e = 1E-2 -> 12.34 e = 1E-3 -> 1.234 ------------------------------------ */ double rp_E( int maxI, double e /* 1E-1 1E-0 1E+1 */ ) { double x; x = (rand() % maxI) + 1 ; /* + 1 : not zero */ x *= e; return(x); } /* ------------------------------------ */ /* ------------------------------------ */