I want to get a random element from 0 to a huge number (2^31).
I tried creating an Array
from such a Range
(so I can use Swift's Array.randomElement
), as done here:
let myArray: [Int64] = [Int64](0...4294967292)
Which compiles, but crashes with:
MyPoject(1569,0x100cc2f40) malloc: can't allocate region mach_vm_map(size=34359738368) failed (error code=3) MyProject(1569,0x100cc2f40) malloc: set a breakpoint in malloc_error_break to debug
Of course, I can write a custom function to create the array, but that smells, especially because the array will be the exact same every time.
Does Swift provide a better solution?