Skip to content

Instantly share code, notes, and snippets.

@gleber
Created February 27, 2009 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gleber/71660 to your computer and use it in GitHub Desktop.
Save gleber/71660 to your computer and use it in GitHub Desktop.
-module(matrix).
-compile(export_all).
random(Size, MaxValue) ->
random(0, 0, Size, MaxValue, [], []).
-define(VALUE(X, Y), value(X, Y, MaxValue)).
value(X, X, _MaxValue) ->
0;
value(_, _, MaxValue) ->
random:uniform(MaxValue).
random(Size, Size, Size, MaxValue, Row, Acc) ->
[[?VALUE(Size, Size) | Row] | Acc];
random(Size, Y, Size, MaxValue, Row, Acc) ->
random(0, Y+1, Size, MaxValue,
[], [[?VALUE(Size, Y) | Row] | Acc]);
random(X, Y, Size, MaxValue, Row, Acc) ->
random(X+1, Y, Size, MaxValue,
[?VALUE(X, Y) | Row], Acc).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment