Julia:生成唯一的随机整数数组 [英] Julia : generating unique random integer array

查看:351
本文介绍了Julia:生成唯一的随机整数数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建10个独特随机整数的元素数组。但是我无法使用唯一值创建数组。朱莉娅有没有像Pythons 样本函数

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)

谢谢。

推荐答案

有一个< StatsBase中的code>样本函数:

using StatsBase
a = sample(1:100, 10, replace = false)

这将从1开始绘制长度为10的样本: 100无需更换。

This will draw a sample of length 10 from 1:100 without replacement.

这篇关于Julia:生成唯一的随机整数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆