[erlang-questions] How random is this

Chandru chandrashekhar.mullaparthi@REDACTED
Wed Oct 10 12:24:41 CEST 2007


On 09/10/2007, Johan Montelius <johanmon@REDACTED> wrote:
>
>
> I needed a procedure that made a process crash with random intervals so I
> wrote someting like this:
>
> -module(crash).
> -export([crash/0]).
>
> crash() ->
>    case random:uniform(100) of
>         X when X < 10 ->
>           true = false;
>         X ->
>           %% io:format("value ~w~n", [X]),
>           ok
>    end.
>
>
> works fine until it actually crashes, then the random function does not
> generate a new value, it's stuck in the value that caused the crash. Could
> be a feature, could be somthing else.
>

Try this instead.

-module(crash).
-export([crash/0]).

crash() ->
    {A, B, C} = now(),
    random:seed(A, B, C),
    crash_1().

crash_1() ->
  case random:uniform(100) of
       X when X < 10 ->
         io:format("value ~w~n", [X]),
         true = false;
       X ->
         crash_1()
  end.



More information about the erlang-questions mailing list