smallcat31
smallcat31

Reputation: 344

Ruby, How to create an n size array of random float from 0 to 1

I know that i can create a random float by calling rand() to generate a (psuedo-)random float between 0 and 1. But what is the best way to create an array of size n of random float between 0 and 1 without using a loop? Thanks!

Upvotes: 1

Views: 256

Answers (1)

BroiSatse
BroiSatse

Reputation: 44685

This would do:

Array.new(n) { rand }

Upvotes: 7

Related Questions