#574 Request: Range.random, List.random

KevinKelley Tue 5 May 2009

No big deal, but I think having Range.random as a shortcut for Int.random(Range) seems nice:

(0..<360).random  // yields a random int in 0 ..< 360

It seems to fit the style of things like

10.times { /*do something*/ }
(1..10).each { /*do something*/ }

which I like.

tactics Tue 5 May 2009

This seems like it would be pretty nice.

In Python, I am also a huge fan of random.choice, which operates on any lenth-computable sequence. For Fan, I wouldn't mind a List.random which returned a random element of the (non-empty) list.

brian Tue 5 May 2009

Promoted to ticket #574 and assigned to brian

will do, I'll add both List.random and Range.random

brian Wed 6 May 2009

Renamed from Request: sys::Range.random to Request: Range.random, List.random

brian Wed 6 May 2009

Ticket resolved in 1.0.42

Login or Signup to reply.