Skip to content

Commit

Permalink
added srandom() YCP builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jan 24, 2013
1 parent a0cfac8 commit 8c04170
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/ruby/ycp/builtins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,19 @@ def self.size object

# Initialize random number generator - srandom(<int>)
# Get the current random number generator seed - int srandom()
def self.srandom
raise "Builtin srandom() is not implemented yet"
def self.srandom *param
if param.empty?
# srandom()
t = Time.now.to_i
srand t
t
else
# srandom(int)
p = param.first

srand p unless p.nil?
nil
end
end

# - Unions of lists
Expand Down
6 changes: 6 additions & 0 deletions tests/ruby/builtins_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,10 @@ def test_isempty
assert_equal false, YCP::Builtins.isempty("foo")
end

def test_srandom
assert_equal nil, YCP::Builtins.srandom(nil)
assert YCP::Builtins.srandom() > 0
assert_equal nil, YCP::Builtins.srandom(10)
end

end

0 comments on commit 8c04170

Please sign in to comment.