1 |
/* rng/file.c |
/* rng/file.c |
2 |
* |
* |
3 |
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough |
* Copyright (C) 2003 Olaf Lenz |
4 |
* |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
55 |
|
|
56 |
return GSL_SUCCESS; |
return GSL_SUCCESS; |
57 |
} |
} |
|
|
|
|
int |
|
|
gsl_rng_fprintf (FILE * stream, const gsl_rng * r, const char * sep) |
|
|
{ |
|
|
size_t n = r->type->size ; |
|
|
|
|
|
unsigned char * state = r->state; |
|
|
|
|
|
size_t i; |
|
|
|
|
|
for (i = 0; i < n; i++) |
|
|
{ |
|
|
int status = fprintf (stream, "%x%s", state[i], sep); |
|
|
|
|
|
if (status < 0) |
|
|
{ |
|
|
GSL_ERROR ("fprintf failed", GSL_EFAILED); |
|
|
} |
|
|
} |
|
|
|
|
|
return GSL_SUCCESS; |
|
|
} |
|
|
|
|
|
int |
|
|
gsl_rng_fscanf (FILE * stream, gsl_rng * r) |
|
|
{ |
|
|
size_t n = r->type->size ; |
|
|
|
|
|
unsigned char * state = r->state; |
|
|
|
|
|
size_t i; |
|
|
|
|
|
for (i = 0; i < n; i++) |
|
|
{ |
|
|
unsigned int j ; |
|
|
|
|
|
int status = fscanf (stream, "%x", &j); |
|
|
|
|
|
j &= 0xff; |
|
|
|
|
|
if (status != 1) |
|
|
{ |
|
|
GSL_ERROR ("fscanf failed", GSL_EFAILED); |
|
|
} |
|
|
|
|
|
state[i] = j; |
|
|
} |
|
|
|
|
|
return GSL_SUCCESS; |
|
|
} |
|
|
|
|