2

I import scala.math._

and print random int sequence just like this form

range = (1 to 5)

print random int sequence (3, 2, 1, 4, 5).

How to do by for loop? T T

1
  • Do you want a random permutation of the range [1, 5] or five independent random numbers? Commented Nov 24, 2011 at 10:59

1 Answer 1

11
import scala.util.Random
for (i <- Random.shuffle((1 to 5).toSeq)) println(i)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.