rand and srand

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: