I am a beginner Julia user and perhaps I am overlooking something obvious but, how can I change a variable in the global scope from within a while loop?
using Distributions
#Constants
const Ropt = 100
const γ= 2
const NumSpecies = 50
const m = sort(rand(Uniform(10^2, 10^12), NumSpecies))
L = @. (m/(m'*Ropt) * exp(1-m/(m'*Ropt)))^γ
L[L .<= 0.01] .= 0
L
#should L be a function? Would it look something like:
# function L(m,Ropt,γ)
# @. (m/(m'*Ropt) * exp(1-m/(m'*Ropt)))^γ
#L[L .<= 0.01] .= 0
#end
FoodWeb = zero(L)
FoodWeb[L .> rand.(Uniform(0, 1))] .= 1
FoodWeb
while (sum(FoodWeb, dims=(1))== 0) & (sum(FoodWeb, dims =(2))==0) #if both a column and a row has all zeros
FoodWeb = zero(L) #I want to redo FoodWeb
FoodWeb[L .> rand.(Uniform(0, 1))] .= 1
return FoodWeb #here I want to stop remaking FoodWeb and place the new values of it into the previous global scope
end
I know that tuples are immutable and perhaps FoodWeb is a tuple?