Skip to content

Commit 9c5ad17

Browse files
author
François Févotte
committed
Init random seed with gettimeofday.usec + pid
1 parent 81c3787 commit 9c5ad17

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ This version is based on Valgrind-3.12.0.
1616
- Continuous integration using the Travis system.
1717
- Improve Delta-Debugging customization through environment variables.
1818

19+
### Changed
1920

21+
- There is no need anymore for an external, statically compiled libc/libm.
22+
23+
24+
---
2025

2126
## v0.9.0 - 2017-03-31
2227

vr_rand.hxx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
#pragma once
3434

35+
extern "C" {
36+
#include "pub_tool_libcproc.h"
37+
}
3538

3639
class vrRand{
3740
public:
@@ -49,7 +52,9 @@ public:
4952
};
5053

5154
inline void setTimeSeed(unsigned int pid){
52-
unsigned int seed=/* time(NULL) + */ pid;
55+
struct vki_timeval now;
56+
VG_(gettimeofday)(&now, NULL);
57+
unsigned int seed = now.tv_usec + pid;
5358
VG_(umsg)("First seed : %u\n",seed);
5459
setSeed(seed);
5560
};
@@ -90,13 +95,13 @@ private:
9095
// srand(c);
9196
vr_next_=c;
9297
}
93-
98+
9499
inline int privaterand(){
95100
// rand();
96101
vr_next_ = vr_next_ * 1103515245 + 12345;
97102
return (unsigned int)(vr_next_/65536) % 32768;
98103
}
99-
104+
100105
inline int privateRAND_MAX()const{
101106
// return RAND_MAX;
102107
return 32767;

0 commit comments

Comments
 (0)