I am trying to create 10 element array of unique random integers. However I am unable to create array with unique values. Is there in Julia something like Pythons sample function ?
numbers = zeros(Array(Int64, 10))
rand!(1:100, numbers)
Thanks.
I am trying to create 10 element array of unique random integers. However I am unable to create array with unique values. Is there in Julia something like Pythons sample function ?
numbers = zeros(Array(Int64, 10))
rand!(1:100, numbers)
Thanks.
There is a sample function in StatsBase:
using StatsBase
a = sample(1:100, 10, replace = false)
This will draw a sample of length 10 from 1:100 without replacement.
A = sample(1:100, 10, 5, replace = false)sample a vector of dimension m*n and then reshape it into a (m, n) matrix.unique(itr[, dim])
Returns an array containing only the unique elements of the iterable itr
unique([rand(1:100) for r in 1:20])[1:10]
Set()
A set is a collection of elements, just like an array or dictionary, with no duplicated elements.
{rand(1:100) for r in 1:20}[1:10]