Skip to main content
added 270 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

Like this:

computeEffect[xEffect_] := With[{offset = RandomInteger[{1, 10}]},
  If[xEffect - offset < 1,
   RandomValue,
   randomA[[xEffect - offset]] + k randomB[[xEffect - offset]]
   ]
  ]

effect = computeEffect /@ Range[1000];

Or

effectLength = 1000;
diffs = Range[effectLength] - RandomInteger[{1, 10}, effectLength];

computeEffect2[diff_] := If[
  diff < 1,
  RandomValue,
  randomA[[diff]] + k randomB[[diff]]
  ]

computeEffect2 /@ diffs

Regarding (2): You don't need to clear the variable before you set it to something else but you do have to initialize it if you want to do it your way. Otherwise it will complain about you trying to access parts of the expression that don't exist. For example list[[5]] = 1 doesn't work if, if list doesn't already have a part 5.

Regarding your last question I could not reproduce the issue. Try to restart the kernel or if it doesn't work please describe how often this happens.

Like this:

computeEffect[xEffect_] := With[{offset = RandomInteger[{1, 10}]},
  If[xEffect - offset < 1,
   RandomValue,
   randomA[[xEffect - offset]] + k randomB[[xEffect - offset]]
   ]
  ]

effect = computeEffect /@ Range[1000];

Regarding (2): You don't need to clear the variable before you set it to something else but you do have to initialize it if you want to do it your way. Otherwise it will complain about you trying to access parts of the expression that don't exist. For example list[[5]] = 1 doesn't work if, if list doesn't already have a part 5.

Regarding your last question I could not reproduce the issue. Try to restart the kernel or if it doesn't work please describe how often this happens.

Like this:

computeEffect[xEffect_] := With[{offset = RandomInteger[{1, 10}]},
  If[xEffect - offset < 1,
   RandomValue,
   randomA[[xEffect - offset]] + k randomB[[xEffect - offset]]
   ]
  ]

effect = computeEffect /@ Range[1000];

Or

effectLength = 1000;
diffs = Range[effectLength] - RandomInteger[{1, 10}, effectLength];

computeEffect2[diff_] := If[
  diff < 1,
  RandomValue,
  randomA[[diff]] + k randomB[[diff]]
  ]

computeEffect2 /@ diffs

Regarding (2): You don't need to clear the variable before you set it to something else but you do have to initialize it if you want to do it your way. Otherwise it will complain about you trying to access parts of the expression that don't exist. For example list[[5]] = 1 doesn't work if, if list doesn't already have a part 5.

Regarding your last question I could not reproduce the issue. Try to restart the kernel or if it doesn't work please describe how often this happens.

Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

Like this:

computeEffect[xEffect_] := With[{offset = RandomInteger[{1, 10}]},
  If[xEffect - offset < 1,
   RandomValue,
   randomA[[xEffect - offset]] + k randomB[[xEffect - offset]]
   ]
  ]

effect = computeEffect /@ Range[1000];

Regarding (2): You don't need to clear the variable before you set it to something else but you do have to initialize it if you want to do it your way. Otherwise it will complain about you trying to access parts of the expression that don't exist. For example list[[5]] = 1 doesn't work if, if list doesn't already have a part 5.

Regarding your last question I could not reproduce the issue. Try to restart the kernel or if it doesn't work please describe how often this happens.