Archive for July 16th, 2010

rand and srand

July 16, 2010

This morning I bit the bullet and revamped srand and rand. srand now takes a Real argument, as per the spec, though it casts it to Int internally. There is also a new version of srand which takes an Any argument and numifies it before calling srand again.

The rand method was worked over to make it work like the other Real methods do now: there’s a Cool version that numifies its argument and calls the rand method on that, a Real version that calls .Bridge on its argument and calls the rand method on that, and a Num version that does the actual work. I also updated the spec to include the rand method, since both the spectests and Rakudo used it, and it seemed to fit with our current way of doing things pretty well.

I’m spectesting these changes as we speak. Assuming no further issues — well, I think I need a little patch to make sure calling srand or rand on a Complex doesn’t cause an infinite loop — I believe the only work remaining for the numeric grant is to tweak the spec a bit to talk about what is expected from Numeric and Real objects in terms of available operators. As always, thanks to The Perl Foundation and Ian Hague for supporting this work.


Follow

Get every new post delivered to your Inbox.