julia 中的随机数

Random Number in julia

我想做一个1到30之间的随机数 我阅读了文档,但找不到执行此操作的方法

例如,我们在 php 中通过

进行
 rand(1 , 30);

我该如何处理

文档中有解释https://docs.julialang.org/en/v1/stdlib/Random/#Base.rand

rand([rng=GLOBAL_RNG], [S], [dims...])

Pick a random element or array of random elements from the set of values specified by S; S can be

  • an indexable collection (for example 1:9 or ('x', "y", :z)),
  • an AbstractDict or AbstractSet object,
  • a string (considered as a collection of characters), or
  • a type: the set of values to pick from is then equivalent to typemin(S):typemax(S) for integers (this is not applicable to BigInt), to [0,1)[0, 1)[0,1) for floating point numbers and to [0,1)+i[0,1)[0, 1)+i[0, 1)[0,1)+i[0,1) for complex floating point numbers;

S defaults to Float64. When only one argument is passed besides the optional rng and is a Tuple, it is interpreted as a collection of values (S) and not as dims.

对于您的示例,它将是

rand(1:30)

您可以将范围传递给 rand 函数以生成两个其他数字之间的数字,包括:

julia> rand(1:30)
24

julia> rand(1:30)
18