mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-22 04:11:16 -05:00
Rationalize random number seeding in C and Fortran
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6272 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
cc6ed82f9a
commit
6be4f3d376
@ -336,6 +336,7 @@ set (wsjt_FSRCS
|
|||||||
lib/hspec.f90
|
lib/hspec.f90
|
||||||
lib/image.f90
|
lib/image.f90
|
||||||
lib/indexx.f90
|
lib/indexx.f90
|
||||||
|
lib/init_random_seed.f90
|
||||||
lib/interleave4.f90
|
lib/interleave4.f90
|
||||||
lib/interleave63.f90
|
lib/interleave63.f90
|
||||||
lib/interleave9.f90
|
lib/interleave9.f90
|
||||||
@ -417,6 +418,7 @@ set (wsjt_CSRCS
|
|||||||
lib/ftrsd/ftrsd2.c
|
lib/ftrsd/ftrsd2.c
|
||||||
lib/gran.c
|
lib/gran.c
|
||||||
lib/igray.c
|
lib/igray.c
|
||||||
|
lib/init_random_seed.c
|
||||||
lib/wsprd/nhash.c
|
lib/wsprd/nhash.c
|
||||||
lib/tab.c
|
lib/tab.c
|
||||||
lib/tmoonsub.c
|
lib/tmoonsub.c
|
||||||
@ -446,6 +448,7 @@ set (wsprd_CSRCS
|
|||||||
lib/wsprd/fano.c
|
lib/wsprd/fano.c
|
||||||
lib/wsprd/tab.c
|
lib/wsprd/tab.c
|
||||||
lib/wsprd/nhash.c
|
lib/wsprd/nhash.c
|
||||||
|
lib/init_random_seed.c
|
||||||
)
|
)
|
||||||
|
|
||||||
set (wsjtx_UISRCS
|
set (wsjtx_UISRCS
|
||||||
|
@ -17,6 +17,8 @@ program code426
|
|||||||
call getarg(2,arg)
|
call getarg(2,arg)
|
||||||
read(arg,*) iters
|
read(arg,*) iters
|
||||||
|
|
||||||
|
call init_random_seed()
|
||||||
|
|
||||||
open(13,file='code426.out',status='unknown')
|
open(13,file='code426.out',status='unknown')
|
||||||
|
|
||||||
write(*,1002) nmsgs,iters
|
write(*,1002) nmsgs,iters
|
||||||
|
@ -45,6 +45,8 @@ program jt4sim
|
|||||||
freq=f0 !Silence compiler warning
|
freq=f0 !Silence compiler warning
|
||||||
dphi=0.0 !Silence compiler warning
|
dphi=0.0 !Silence compiler warning
|
||||||
|
|
||||||
|
call init_random_seed()
|
||||||
|
|
||||||
h=default_header(12000,npts)
|
h=default_header(12000,npts)
|
||||||
|
|
||||||
if(message(1:3).eq.'sin') read(message(4:),*) sinfreq
|
if(message(1:3).eq.'sin') read(message(4:),*) sinfreq
|
||||||
|
@ -35,6 +35,8 @@ program jt65sim
|
|||||||
go to 999
|
go to 999
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
call init_random_seed(1)
|
||||||
|
|
||||||
csubmode='A'
|
csubmode='A'
|
||||||
call getarg(1,csubmode)
|
call getarg(1,csubmode)
|
||||||
mode65=1
|
mode65=1
|
||||||
@ -62,9 +64,6 @@ program jt65sim
|
|||||||
h=default_header(12000,npts)
|
h=default_header(12000,npts)
|
||||||
dfsig=2000.0/nsigs !Freq spacing between sigs in file (Hz)
|
dfsig=2000.0/nsigs !Freq spacing between sigs in file (Hz)
|
||||||
|
|
||||||
! generate new random number seed for each run using /dev/urandom on linux and os x
|
|
||||||
! nerr=sgran()
|
|
||||||
|
|
||||||
do ifile=1,nfiles !Loop over requested number of files
|
do ifile=1,nfiles !Loop over requested number of files
|
||||||
write(fname,1002) ifile !Output filename
|
write(fname,1002) ifile !Output filename
|
||||||
1002 format('000000_',i4.4)
|
1002 format('000000_',i4.4)
|
||||||
|
@ -17,6 +17,7 @@ Information-carrying channel symbols
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "rs.h"
|
#include "rs.h"
|
||||||
|
#include "init_random_seed.h"
|
||||||
|
|
||||||
static void *rs;
|
static void *rs;
|
||||||
|
|
||||||
@ -35,6 +36,8 @@ int main(){
|
|||||||
int mrsym[63],mrprob[63],mr2sym[63],mr2prob[63];
|
int mrsym[63],mrprob[63],mr2sym[63],mr2prob[63];
|
||||||
int nsec2,ncount,dat4[12];
|
int nsec2,ncount,dat4[12];
|
||||||
|
|
||||||
|
init_random_seed();
|
||||||
|
|
||||||
datfile=fopen("kvasd.dat","rb");
|
datfile=fopen("kvasd.dat","rb");
|
||||||
if( !datfile ) {
|
if( !datfile ) {
|
||||||
printf("Unable to open kvasd.dat\n");
|
printf("Unable to open kvasd.dat\n");
|
||||||
@ -96,11 +99,11 @@ int main(){
|
|||||||
printf("num_errors = %d\n",num_errors);
|
printf("num_errors = %d\n",num_errors);
|
||||||
for( i=0; i<num_errors; i++) {
|
for( i=0; i<num_errors; i++) {
|
||||||
do {
|
do {
|
||||||
errval = random() & nn;
|
errval = rand() & nn;
|
||||||
} while(errval == 0); //generate random
|
} while(errval == 0); //generate random
|
||||||
|
|
||||||
do {
|
do {
|
||||||
errloc = random() % nn;
|
errloc = rand() % nn;
|
||||||
} while(errlocs[errloc]!=0);
|
} while(errlocs[errloc]!=0);
|
||||||
|
|
||||||
errlocs[errloc] = errval;
|
errlocs[errloc] = errval;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "rs.h"
|
#include "rs.h"
|
||||||
|
#include "init_random_seed.h"
|
||||||
|
|
||||||
static void *rs;
|
static void *rs;
|
||||||
|
|
||||||
@ -175,12 +176,9 @@ int main(int argc, char *argv[]){
|
|||||||
// "soft" distance between each codeword and the received word is
|
// "soft" distance between each codeword and the received word is
|
||||||
// used to decide which codeword is "best".
|
// used to decide which codeword is "best".
|
||||||
//
|
//
|
||||||
// srandom(time(NULL));
|
|
||||||
#ifdef WIN32
|
init_random_seed();
|
||||||
srand(0xdeadbeef);
|
|
||||||
#else
|
|
||||||
srandom(0xdeadbeef);
|
|
||||||
#endif
|
|
||||||
float p_erase;
|
float p_erase;
|
||||||
int thresh, nsum;
|
int thresh, nsum;
|
||||||
ncandidates=0;
|
ncandidates=0;
|
||||||
@ -207,11 +205,7 @@ int main(int argc, char *argv[]){
|
|||||||
}
|
}
|
||||||
thresh = p_erase*100;
|
thresh = p_erase*100;
|
||||||
long int ir;
|
long int ir;
|
||||||
#ifdef WIN32
|
|
||||||
ir=rand();
|
ir=rand();
|
||||||
#else
|
|
||||||
ir=random();
|
|
||||||
#endif
|
|
||||||
if( ((ir % 100) < thresh ) && numera < 51 ) {
|
if( ((ir % 100) < thresh ) && numera < 51 ) {
|
||||||
era_pos[numera]=indexes[62-i];
|
era_pos[numera]=indexes[62-i];
|
||||||
numera=numera+1;
|
numera=numera+1;
|
||||||
|
13
lib/sgran.c
13
lib/sgran.c
@ -1,15 +1,8 @@
|
|||||||
#include <stdio.h>
|
#include "init_random_seed.h"
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
/* seed rand using urandom */
|
/* seed rand */
|
||||||
float sgran_()
|
float sgran_()
|
||||||
{
|
{
|
||||||
unsigned int seed;
|
init_random_seed();
|
||||||
FILE *urandom;
|
|
||||||
urandom = fopen ("/dev/urandom","r");
|
|
||||||
fread (&seed, sizeof (seed), 1, urandom);
|
|
||||||
srand (seed);
|
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ program t1
|
|||||||
call getarg(3,arg)
|
call getarg(3,arg)
|
||||||
read(arg,*) iters
|
read(arg,*) iters
|
||||||
|
|
||||||
|
call init_random_seed()
|
||||||
call random_number(r)
|
call random_number(r)
|
||||||
itone=0
|
itone=0
|
||||||
where(r.gt.0.5) itone=1
|
where(r.gt.0.5) itone=1
|
||||||
|
8
lib/test_init_random_seed.f90
Normal file
8
lib/test_init_random_seed.f90
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
program test_init_random_seed
|
||||||
|
real :: r(10,4)
|
||||||
|
call init_random_seed()
|
||||||
|
call random_number(r)
|
||||||
|
do i =1,10
|
||||||
|
write (*, *) (r(i,j),j=1,4)
|
||||||
|
end do
|
||||||
|
end program test_init_random_seed
|
@ -40,6 +40,7 @@
|
|||||||
#include "nhash.h"
|
#include "nhash.h"
|
||||||
#include "wsprd_utils.h"
|
#include "wsprd_utils.h"
|
||||||
#include "wsprsim_utils.h"
|
#include "wsprsim_utils.h"
|
||||||
|
#include "lib/init_random_seed.h"
|
||||||
|
|
||||||
#define max(x,y) ((x) > (y) ? (x) : (y))
|
#define max(x,y) ((x) > (y) ? (x) : (y))
|
||||||
// Possible PATIENCE options: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT,
|
// Possible PATIENCE options: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT,
|
||||||
@ -615,6 +616,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
int uniques=0, noprint=0;
|
int uniques=0, noprint=0;
|
||||||
|
|
||||||
|
init_random_seed();
|
||||||
|
|
||||||
// Parameters used for performance-tuning:
|
// Parameters used for performance-tuning:
|
||||||
maxcycles=10000; //Fano timeout limit
|
maxcycles=10000; //Fano timeout limit
|
||||||
double minsync1=0.10; //First sync limit
|
double minsync1=0.10; //First sync limit
|
||||||
|
Loading…
Reference in New Issue
Block a user