How does that pattern matching example work?

I saw that pattern matching in Ecto.UUID module. But in that example right and left elements are not equal. Can you please explain to me ? And what does this mean b1::4 or u1::12


<< a1::4, a2::4, a3::4, a4::4, a5::4, a6::4, a7::4, a8::4,
 b1::4, b2::4, b3::4, b4::4, c1::4, c2::4, c3::4, c4::4, 
d1::4, d2::4, d3::4, d4::4, e1::4, e2::4, e3::4, 
e4::4, e5::4, e6::4, e7::4, e8::4, e9::4, e10::4, e11::4, e12::4 >> = :crypto.strong_rand_bytes(16)
#example output from :crypto.strong_rand_bytes(16)
:crypto.strong_rand_bytes(16)
<<179, 13, 74, 153, 186, 216, 170, 200, 121, 18, 247, 67, 87, 155, 221, 23>>

b1::4 means b1 would match 4 bits. And u1::12 means u1 would match 12 bits.

In the pattern on the left you have 32*4=128 bits which is the same as on the right (16 “random” bytes = 8 * 16 = 128 bits).

4 Likes