Lartu / ldpl

COBOL-like programming language that compiles to C++. With serious dinosaurs with neckties and briefcases 🦕💼
https://www.ldpl-lang.org/
Apache License 2.0
158 stars 24 forks source link

Random numbers not so random #90

Closed xvxx closed 5 years ago

xvxx commented 5 years ago

Maybe the seed is constant by accident? I get the same results each time, it seems:

$ cat rand.ldpl 
DATA:
r is number
i is number

PROCEDURE:
while i is less than 5 do
  store random in r
  display r crlf
  incr i
repeat

$ for i in {1..5}; do echo "# ${i}"; ./rand-bin; done
# 1
0.365382414946976
0.982248013830859
0.642368455250919
0.28662740219693
0.346748723809956
# 2
0.365382414946976
0.982248013830859
0.642368455250919
0.28662740219693
0.346748723809956
# 3
0.365382414946976
0.982248013830859
0.642368455250919
0.28662740219693
0.346748723809956
# 4
0.365382414946976
0.982248013830859
0.642368455250919
0.28662740219693
0.346748723809956
# 5
0.365382414946976
0.982248013830859
0.642368455250919
0.28662740219693
0.346748723809956
dgarroDC commented 5 years ago

It seems that the problem is that std::time has a resolution on seconds.

Lartu commented 5 years ago

There, it's fixed now using the C++11 header.

xvxx commented 5 years ago

Works great! :+1:

Lartu commented 5 years ago

Awesome! :smile: