Abhishek Kumar - 1 year ago 60

Scala Question

`Seq.fill(n)(math.pow(Random.nextFloat,2) + math.pow(Random.nextFloat,2)).filter(_<1).size.toFloat/n*4`

Basically this scala code checks number of times a random points comes out of first quadrant of a unit circle. For large values of

`n`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

If you use an `Iterator`

no intermediate collection has to be created in memory.

```
Iterator.fill(n)(math.pow(Random.nextFloat,2) + math.pow(Random.nextFloat,2)).filter(_<1).size.toFloat/n*4
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**