Julia : generating unique random integer array

后端 未结 3 1022
礼貌的吻别
礼貌的吻别 2021-02-19 12:08

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 functio

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 12:38

    If performance is not an issue (i.e. the sample range isn't too large, or the sample count is close to the sample range), and if you don't want to use an additional package for whatever reason, try:

    a = randperm(100)[1:10]

提交回复
热议问题