Hello,
Just got started. I want to call a function from another function. Here is a snippet of code I’m using as a test.
tester[]:=
w=RandomInteger[{-10,10}];
t=Table[tester[],{i,9}];
t
Out[3]= {4,8,-6,4,5,-10,8,1,-3}
checkarray[entry_,nproblems_]:=
Table[entry,{i,1,nproblems}];
out=checkarray[tester[],5]
{8,8,8,8,8}
I want the checkarray function to write a Table with n random values, but it writes one value n times. So what’s happening here?
My guess is that your problem is about immediate and delayed assignments. Since tester[] has delayed assignment, RandomInteger is evaluated afresh every time you call tester[]. If you call tester[] repeatedly you get different random values, but calling w gets the same value. This is because w=RandomInteger[{-10,10}] stores the value of w in memory straight away, and it doesn’t change until you call tester[] again.
I can’t see what your definition of checkarray is. You introduce the variable w and then you don’t use it.What is entry?
w was just meant to check the output, not a part of the function. Changearray will eventually check an array for duplicates. First I have to get it to create an array inside the function. I want Changearray to check for duplicates .(eventually)
I didn’t answer your question. Entry is intended to be a value generated randomly by another function that calls RandomInteger.