OpenCores
URL https://opencores.org/ocsvn/gng/gng/trunk

Subversion Repositories gng

[/] [gng/] [trunk/] [matlab/] [ctg_seed.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 guangxi.li
/*
2
 * Generate Combined Tausworthe Generator seed
3
 *
4
 * The calling syntax is:
5
 *     z = ctg_seed(s)
6
 *
7
 * Input:
8
 *     s: seed, unsigned 32-bit integer
9
 *
10
 * Output:
11
 *     z: initial internal state, 3 x 1 vector of unsigned 64-bit integer
12
 */
13
 
14
#include "mex.h"
15
#include "taus176.h"
16
 
17
 
18
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
19
{
20
    /* Local variables */
21
    taus_state_t state;
22
    double *s;
23
    unsigned seed;
24
    unsigned long long *z;
25
 
26
    /* Check for proper number of arguments */
27
    if (nrhs != 1)
28
        mexErrMsgTxt("One input arguments required.");
29
    else if (nlhs > 1)
30
        mexErrMsgTxt("Too many output arguments.");
31
 
32
    if (!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||
33
            (mxGetM(prhs[0]) != 1) || (mxGetN(prhs[0]) != 1))
34
        mexErrMsgTxt("ctg_seed requires that s be a unsigned 32-bit integer.");
35
 
36
    /* Create a vector for the return argument */
37
    plhs[0] = mxCreateNumericMatrix(3, 1, mxUINT64_CLASS, 0);
38
 
39
    /* Assign pointers to the various parameters */
40
    s = (unsigned *)mxGetPr(prhs[0]);
41
    seed = (unsigned)(*s);
42
    z = (unsigned long long*)mxGetData(plhs[0]);
43
 
44
    /* Call function taus_set */
45
    taus_set(&state, seed);
46
 
47
    /* Assign return value */
48
    z[0] = state.z1;
49
    z[1] = state.z2;
50
    z[2] = state.z3;
51
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.