1. 程式人生 > >linux 獲取隨機數函式

linux 獲取隨機數函式

--------------------y.cpp---------------------

/*
 * y.cpp
 *
 *  Created on: 2013-12-15
 *      Author: root
 */

#include "y.h"

unsigned long GetRandomNumber()
{
    struct timeval tpstart;

    gettimeofday(&tpstart, NULL);

    srand(tpstart.tv_usec);

    unsigned long x = rand();

    return x;
}

-----------------y.h-------------------------------
/*
 * y.h
 *
 *  Created on: 2013-12-15
 *      Author: root
 */

#ifndef Y_H_
#define Y_H_

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>

unsigned long GetRandomNumber();
#endif /* Y_H_ */