From b849062c5aa3f54d4cda7df8a2b1ff98137405e3 Mon Sep 17 00:00:00 2001 From: Zesky665 Date: Fri, 13 May 2016 19:14:45 +0200 Subject: [PATCH 1/2] Replaced depreceated :erlang function The function :erlang.now() is considered deprecated, the ERST recommends using :erlang.timestamp\0 instead. --- ch06-lists.asciidoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ch06-lists.asciidoc b/ch06-lists.asciidoc index 154fd0b..05c2e90 100644 --- a/ch06-lists.asciidoc +++ b/ch06-lists.asciidoc @@ -303,15 +303,15 @@ iex(1)> :random.uniform() 0.4435846174457203 ----- -Now, exit +iex+, restart, and type the same command again. You'll get the same number. In order to ensure that you get different sets of random numbers, you have to _seed_ the random number generator with a three-tuple. The easiest way to get a different seed every time you run the program is to use the +:erlang.now/0+ built-in function, which returns a different three-tuple every time you call it. +Now, exit +iex+, restart, and type the same command again. You'll get the same number. In order to ensure that you get different sets of random numbers, you have to _seed_ the random number generator with a three-tuple. The easiest way to get a different seed every time you run the program is to use the +:erlang.now/0+,(+:erlang.now/0+ is considered deprecated, use +:erlang.timestamp\0+ instead) built-in function, which returns a different three-tuple every time you call it. // [source,iex] ----- iex(1)> :erlang.now() {1368,203897,899678} -iex(2)> :erlang.now() +iex(2)> :erlang.timestamp() {1368,203904,416818} -iex(3)> :erlang.now() +iex(3)> :erlang.timestamp() {1368,203909,179152} ----- @@ -322,7 +322,7 @@ random number generator wasn't seeded before. // [source,iex] ------ -iex(1)> :random.seed(:erlang.now()) +iex(1)> :random.seed(:erlang.timestamp()) :undefined iex(2)> :random.uniform() 0.4102329513116634 From b20bbae730ebca9e5fdb1cbb8c11ba8c6be26c10 Mon Sep 17 00:00:00 2001 From: Zesky665 Date: Fri, 13 May 2016 19:19:32 +0200 Subject: [PATCH 2/2] Replaced depreceated :erlang function Replaced deprecated :erlang.now() function with :erlang.timestamp() as suggested in the ERTS: http://erlang.org/doc/apps/erts/time_correction.html --- code/ch06-04/non_fp.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ch06-04/non_fp.ex b/code/ch06-04/non_fp.ex index 5bfb460..366858a 100644 --- a/code/ch06-04/non_fp.ex +++ b/code/ch06-04/non_fp.ex @@ -17,7 +17,7 @@ defmodule NonFP do @spec generate_pockets(list, number) :: list(list) def generate_pockets(tooth_list, prob_good) do - :random.seed(:erlang.now()) + :random.seed(:erlang.timestamp()) generate_pockets(tooth_list, prob_good, []) end