~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavutil/random_seed.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <unistd.h>
22
22
#include <fcntl.h>
 
23
#include <math.h>
 
24
#include <time.h>
23
25
#include "timer.h"
24
 
#include "time.h"
25
26
#include "random_seed.h"
26
 
#include "avutil.h"
27
27
 
28
28
static int read_random(uint32_t *dst, const char *file)
29
29
{
40
40
 
41
41
static uint32_t get_generic_seed(void)
42
42
{
43
 
    clock_t last_t=0;
44
 
    int bits=0;
45
 
    uint64_t random=0;
 
43
    clock_t last_t  = 0;
 
44
    int bits        = 0;
 
45
    uint64_t random = 0;
46
46
    unsigned i;
47
 
    float s=0.000000000001;
 
47
    float s = 0.000000000001;
48
48
 
49
 
    for(i=0;bits<64;i++){
50
 
        clock_t t= clock();
51
 
        if(last_t && fabs(t-last_t)>s || t==(clock_t)-1){
52
 
            if(i<10000 && s<(1<<24)){
53
 
                s+=s;
54
 
                i=t=0;
55
 
            }else{
56
 
                random= 2*random + (i&1);
 
49
    for (i = 0; bits < 64; i++) {
 
50
        clock_t t = clock();
 
51
        if (last_t && fabs(t - last_t) > s || t == (clock_t) -1) {
 
52
            if (i < 10000 && s < (1 << 24)) {
 
53
                s += s;
 
54
                i = t = 0;
 
55
            } else {
 
56
                random = 2 * random + (i & 1);
57
57
                bits++;
58
58
            }
59
59
        }
60
 
        last_t= t;
 
60
        last_t = t;
61
61
    }
62
62
#ifdef AV_READ_TIME
63
63
    random ^= AV_READ_TIME();
65
65
    random ^= clock();
66
66
#endif
67
67
 
68
 
    random += random>>32;
 
68
    random += random >> 32;
69
69
 
70
70
    return random;
71
71
}