0

I'm trying to generate a unique random sequence of 50 Binary strings of size 36 bits each. I tried doing nextInt followed by toBinaryString which didn't solve my problem as nextInt don't support such big numbers and also checked nextString which generates string of some random characters (not 0/1) is there any other way to achieve this ? And to add one more requirement I want 36 bits to be present at every time suppose if some random generator generated 3 as a number I want the output as 000...(34)11.

I'm quite new to scala, Pardon me if my question seemed irrelavant or redundant.

1
  • 1
    What do you mean by "binary string of size 36 bits"? Is it string or number or byte array? Commented Apr 19, 2019 at 4:45

1 Answer 1

1

You can try

val r = scala.util.Random
val a: immutable.Seq[Int] = (0 to 50).map(_ => r.nextInt(1000000))
val y = a.map( x => {
   val bin = x.toBinaryString
   val zero = 36 - bin.length
   List.fill(zero)(0).mkString("") ++ bin
})
println(Random.shuffle(y))
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.