 <?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.analytica.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=HEshraghi</id>
	<title>Analytica Docs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.analytica.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=HEshraghi"/>
	<link rel="alternate" type="text/html" href="https://docs.analytica.com/index.php/Special:Contributions/HEshraghi"/>
	<updated>2026-05-30T15:52:25Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>https://docs.analytica.com/index.php?title=Iterate&amp;diff=56520</id>
		<title>Iterate</title>
		<link rel="alternate" type="text/html" href="https://docs.analytica.com/index.php?title=Iterate&amp;diff=56520"/>
		<updated>2021-06-30T21:32:46Z</updated>

		<summary type="html">&lt;p&gt;HEshraghi: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[category:Evaluation Functions]]&lt;br /&gt;
[[category:Top level functions]]&lt;br /&gt;
[[Category:Doc Status D]] &amp;lt;!-- For Lumina use, do not change --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Iterate(initial, expr, until'', maxIter, warn'') ==&lt;br /&gt;
Repeats the computation «expr» until the termination condition «until» becomes true (nonzero), or the number of iterations reaches «maxIter».  The parameters «expr» and «until» may, and usually do, depend on variable(s) that depends on the variable defined with Iterate. This creates a recurrence,  [[Draw arrows#Influence cycle or loop|cycle or loop]] in the influence diagram, something that is not otherwise allowed except in [[Dynamic]] loops.  Analytica iterates the evaluation around the cycle until it reaches the termination condition «until», usually a convergence or equilibrium.&lt;br /&gt;
&lt;br /&gt;
You may use [[Iterate]] only as the main function defining a variable (as with [[Dynamic]]). You may not nest it inside an expression. &lt;br /&gt;
&lt;br /&gt;
'''Parameters:'''&lt;br /&gt;
* «initial»: the starting value for the iteration&lt;br /&gt;
* «expr»: how the subsequent values are computed from the previous value.  «expr» may, and usually does, depend directly or indirectly upon the variable defined by Iterate, forming a recurrence or cycle in the influence diagram.  &lt;br /&gt;
* «until»: The termination condition.  Iterate continues evaluating «expr» until «until» is true (non-zero) -- if «until» is an array, until all its elements are true (nonzero) -- or until the number of iterations reaches «maxIter», if specif.  &lt;br /&gt;
* ''«maxIter»'': (optional) The maximum number of iterations. If omitted, it will keep iterating until the «until» becomes true. Unless you are absolutely certain the iteration will converge, it is a good idea to specify a value for «maxinter».&lt;br /&gt;
* ''«warn»'': (optional) If true (nonzero), it will give a warning if it terminates due to reaching the maximum number of iterations «maxinter», rather than the termination condition «until».&lt;br /&gt;
&lt;br /&gt;
[[Iterate]] is useful when you want adjust a variable and repeat a calculation over several variables in the model to meet a constraint. If you can perform the iteration within the definition of a single variable or [[User-Defined Functions]], it is usually simpler and clearer to use the [[While..Do]] construct.&lt;br /&gt;
&lt;br /&gt;
For more complex cases, especially when you want to adjust multiple variables to solve constraints and/or find a maximum or minimum, it is simpler and faster to use the [[Analytica Optimizer Guide|Analytica Optimizer]].&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
:[[Image:Market Equilibrary Diagram.jpg]]&lt;br /&gt;
&lt;br /&gt;
This example models how a market price reaches equilibrium to correct an imbalance between supply and demand.  It forecasts a the supply and demand given an initial price, and modifies the &amp;lt;code&amp;gt;Price&amp;lt;/code&amp;gt; iteratively until the supply exactly matches the demand reaching a market equilibrium.  &amp;lt;code&amp;gt;Price&amp;lt;/code&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;Price := Iterate(Price_Guess, Next_price, Abs(Next_price-price) &amp;lt; 0.01, 50)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It iterates until the change in price between successive iterations is less than 0.01, or reaches 50 iterations.&lt;br /&gt;
&lt;br /&gt;
== Iterating Multiple Variables ==&lt;br /&gt;
You may want to update several variables in each iteration:  For example, both &amp;lt;code&amp;gt;Price&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Market_size&amp;lt;/code&amp;gt;.  You should define  only one variable using [[Iterate]]. (If you define both &amp;lt;code&amp;gt;Price&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Market_size&amp;lt;/code&amp;gt; using [[Iterate]], it will create two nested iterations, which would not do what you want.) Instead, you can define a new single variable that groups all the variables into a single state, listing them along an index.&lt;br /&gt;
&lt;br /&gt;
:[[Image:Market Equilib Diagram2.jpg]]&lt;br /&gt;
&lt;br /&gt;
In the above diagram, &amp;lt;code&amp;gt;State_index&amp;lt;/code&amp;gt; is defined as a list of labels:&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! State_index &amp;amp;#9660;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;Price&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
| &amp;quot;Market Size&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
You define the initial state and next state each as a table indexed by &amp;lt;code&amp;gt;State_index&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;Variable Initial_state := Table(State_index)(Price_Guess, Market_size_guess)&amp;lt;/code&amp;gt;&lt;br /&gt;
:&amp;lt;code&amp;gt;Variable Next_State := Table(State_Index)(Price_Guess, Market_size_guess)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and define &amp;lt;code&amp;gt;State&amp;lt;/code&amp;gt; using Iterate:&lt;br /&gt;
:&amp;lt;code&amp;gt;Variable State := Iterate(Initial_state, Next_State, abs(state-next_state) &amp;lt; 0.01, 50)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For convenience in the rest of the model, it is useful to define &amp;lt;code&amp;gt;Price&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Market_Size&amp;lt;/code&amp;gt; as the elements of &amp;lt;code&amp;gt;State&amp;lt;/code&amp;gt;: &lt;br /&gt;
:&amp;lt;code&amp;gt;Variable Price := State[State_Index = 'Price']&amp;lt;/code&amp;gt;&lt;br /&gt;
:&amp;lt;code&amp;gt;Variable Market_Size := State[State_Index = 'Market Size']&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So far, we assume that &amp;lt;code&amp;gt;State&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Market_size&amp;lt;/code&amp;gt; have the same dimensions -- both are scalars, or both are arrays with the same indexes.  If you want them to have different dimensions, you can include their values using [[Using References|references]]:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;Variable Initial_state := &amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;Table(State_index)(\Price_guess, \Market_size_guess)&amp;lt;/code&amp;gt;&lt;br /&gt;
:&amp;lt;code&amp;gt;Variable Next_state := &amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;Table(State_Index)(\Price_Guess, \Market_size_guess)&amp;lt;/code&amp;gt;&lt;br /&gt;
:&amp;lt;code&amp;gt;Variable Price := &amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;#State[State_index = 'Price']&amp;lt;/code&amp;gt;&lt;br /&gt;
:&amp;lt;code&amp;gt;Variable Market_size :=&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;#State[State_index = 'Market Size']&amp;lt;/code&amp;gt;&lt;br /&gt;
:&amp;lt;code&amp;gt;Variable State :=&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;code&amp;gt;Iterate(Initial_state, Next_State, &amp;lt;/code&amp;gt;&lt;br /&gt;
:::&amp;lt;code&amp;gt;Abs(Price-next_price) &amp;lt; 0.01 AND Abs(Market_size - Next_market_size) &amp;lt; 1, &amp;lt;/code&amp;gt;&lt;br /&gt;
:::&amp;lt;code&amp;gt;50)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that '[[Using References|\]]' and '[[#]]' are the reference and de-reference operators. Gathering references to values into an array is a flexible method that generalizes to any number of variables. &lt;br /&gt;
&lt;br /&gt;
== Iterate with Dynamic ==&lt;br /&gt;
Iterate can be used in conjunction with [[Dynamic]].  Depending on the model structure, this can either result in an iteration within a dynamic loop, where the iteration to convergence occurs at each point in time, or it can result in a dynamic loop within an iteration, in which case the entire dynamic loop is computed to completion within each iteration.&lt;br /&gt;
&lt;br /&gt;
Suppose &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; is a variable defined with Iterate, and &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt; is a variable defined with [[Dynamic]].  Then &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; might depend directly or indirectly on &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt; might depend directly or indirectly on &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt;.  This creates four distinct dependency structures.  When neither &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; nor &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt; depends on the other, then there is no interaction.  Similarly, when &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt; depends on &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt;, but &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; is not downstream of &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt;, then &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; is not within &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt;'s dynamic loop, so again there is no interaction.  In this case, &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; is iterated to completion once, independent of the dynamic loop, then the dynamic loop performs its looping using this value.  &lt;br /&gt;
&lt;br /&gt;
When &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; depends on &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt;, but &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt; does not depend on &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt;, then the dynamic loop is completely inside the Iteration for &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt;, so that the dynamic loop is computed to completion within each iteration.  &lt;br /&gt;
&lt;br /&gt;
The most difficult case is when &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt; both depend on the other.  When this happens, the iterate expression could, in principle, be interpreted as being inside the dynamic or around the dynamic.  Analytica resolves this ambiguity by assuming that the iterate is inside the dynamic, so that as the dynamic loop is evaluated at each time period, the iteration in &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; is run to completion for that time period.  Variables inside &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt;'s definition are implicitly assumed to be sliced by the current dynamic time (as occurs with any variable appearing inside a dynamic loop).&lt;br /&gt;
&lt;br /&gt;
You may encounter situations where you want to compute one or more variables using Iterate, which in turn are utilized within a dynamic loop, but where you desire the iteration to occur around the dynamic loop.  For example, you may have completed an entire [[Dynamic]] model, and now you want to wrap [[Iterate]] around the full model to adjust an input parameter.  In the future, we may introduce a new variation on the iterate function that would make it possible to specify that [[Iterate]] is wrapped around a given dynamic loop.  Until then, one way to cause Iterate to wrap around a dynamic loop is by using a [[WhatIf]] to compute the value of the input parameter.  To demonstrate, suppose you have an input parameter, &amp;lt;code&amp;gt;K&amp;lt;/code&amp;gt;, used by a dynamic model having some output &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt;.  We want to define &amp;lt;code&amp;gt;K&amp;lt;/code&amp;gt; using [[Iterate]] where the update expression and termination expressions depend on &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt;.  To do this, we introduce two variables:&lt;br /&gt;
:&amp;lt;code&amp;gt;Variable Y2 := WhatIf(Y, K, K2)&amp;lt;/code&amp;gt;&lt;br /&gt;
:&amp;lt;code&amp;gt;Variable K2 := Iterate(K, f(K2, Y2), g(K2, Y2))&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;f()&amp;lt;/code&amp;gt; is the update expression and &amp;lt;code&amp;gt;g()&amp;lt;/code&amp;gt; is the termination expression.  When &amp;lt;code&amp;gt;K2&amp;lt;/code&amp;gt; is evaluated, the iteration re-evaluates the full model repeatedly, with &amp;lt;code&amp;gt;K2&amp;lt;/code&amp;gt; eventually being set to the &amp;quot;converged&amp;quot; value for the parameter &amp;lt;code&amp;gt;K&amp;lt;/code&amp;gt;.  As a final step, we may want to set &amp;lt;code&amp;gt;K&amp;lt;/code&amp;gt; to be this computed value for &amp;lt;code&amp;gt;K2&amp;lt;/code&amp;gt;.  For this last step, we would need to use a button:&lt;br /&gt;
:&amp;lt;code&amp;gt;Button Update_K := (K := K2)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pressing the button causes the entire evaluation to take place.  &lt;br /&gt;
&lt;br /&gt;
(To do: provide some examples)&lt;br /&gt;
&lt;br /&gt;
== Interacting Iterate Functions ==&lt;br /&gt;
If you have two (or more) variables defined using the [[Iterate]] function, they should not be mutually dependent on each other.  This case creates an ambiguity (for example, the result would depend on which was evaluated first), and results in an error message.&lt;br /&gt;
&lt;br /&gt;
It is okay for one to be nested within the other, in which case the inner iteration runs to convergence during each iteration of the outer iterate. However, the need for nested iterations like this are rare. You should make sure that you don't intend to have a single iteration with multiple variables updated in the same iteration (see the earlier section on this page).&lt;br /&gt;
&lt;br /&gt;
If you have two interacting Iterate loops that are not clearly nested, you will see this error message:&lt;br /&gt;
&lt;br /&gt;
:''A disallowed cyclic dependency involving the Iterate function in ''ident'' detected.  You may have two nodes  defined with Iterate functions, with each depending on the other.  If you use two Iterate functions, one needs  to be clearly nested inside the other.  If you intend to have a single iteration involving two or more nodes,  the Iterate function should appear only once.''&lt;br /&gt;
&lt;br /&gt;
=== Iterate with Change in Evaluation Mode ===&lt;br /&gt;
Suppose &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; is defined using [[Iterate]], and the update expression depends on [[Sample]](X) -- for example, it may use a statistical function like [[Mean]](X).  If &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt; is evaluated in [[Mid]] mode, it appears as if there are two interacting Iterate loops, and the above error message, ''A disallowed cyclic dependency involving Iterate....'' occurs.&lt;br /&gt;
&lt;br /&gt;
== Iterate vs. While..Do ==&lt;br /&gt;
[[Iterate]] and [[While..Do]] are closely related, and both are often used for implementing convergence algorithms.  When implementing an iterative algorithm in a [[User-Defined Functions|User-Defined Function]], you would normally use [[While..Do]].  However, in some situations you may develop a fairly sizable influence diagram model, where you wish to iterate over the entire model.  In that case, Iterate is very convenient, and may require only small modifications.&lt;br /&gt;
&lt;br /&gt;
The [[While..Do]] construct requires its parameter, which determines when the loop terminates, to be atomic, while [[Iterate]] allows array-valued termination conditions, but continues until all cells are true.  &lt;br /&gt;
&lt;br /&gt;
There are a few other approaches to implementing iterations within Analytica.  [[NlpDefine]] performs a full optimization search.  The [[Solve]] and [[GoalSeek]] functions are similar, although scaled down somewhat in their sophistication.  [[User-Defined Functions]] can be recursive, although the [[recursion]] depth is usually limited to 255, which can be a limiting factor.  And to iterate over an existing model structure, [[While..Do]] can be used with [[WhatIf]], or from a button script, [[While..Do]] can be used with assignment (often a useful way to iterate in very large scale sampling applications that exceed memory required for built-in Monte Carlo sampling).  And of course, there is [[Dynamic]].&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[Analytica_User_Group/Past_Topics#The_Iterate_Function|Webinar on the Iterate Function]]&lt;br /&gt;
* [[Dynamic]]&lt;br /&gt;
* [[ComputedBy]]&lt;br /&gt;
* [[While..Do]]&lt;br /&gt;
* [[Using References]]&lt;br /&gt;
* [[DefineOptimization]]&lt;br /&gt;
* [[WhatIf]]&lt;br /&gt;
* [[Recursion]]&lt;br /&gt;
* &amp;lt;code&amp;gt;Newton Raphson Method.ana&amp;lt;/code&amp;gt; example model in the &amp;lt;code&amp;gt;Example Models/Decision Analysis folder&amp;lt;/code&amp;gt; installed with Analytica&lt;/div&gt;</summary>
		<author><name>HEshraghi</name></author>
	</entry>
	<entry>
		<id>https://docs.analytica.com/index.php?title=ChanceDist_-_Custom_discrete_distribution&amp;diff=56519</id>
		<title>ChanceDist - Custom discrete distribution</title>
		<link rel="alternate" type="text/html" href="https://docs.analytica.com/index.php?title=ChanceDist_-_Custom_discrete_distribution&amp;diff=56519"/>
		<updated>2021-06-30T20:03:51Z</updated>

		<summary type="html">&lt;p&gt;HEshraghi: Remove a usage section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[category:Custom distributions]]&lt;br /&gt;
[[category:Discrete distributions]]&lt;br /&gt;
[[Category:Doc Status C]] &amp;lt;!-- For Lumina use, do not change --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ChanceDist(P, A, I) ==&lt;br /&gt;
&lt;br /&gt;
Creates a discrete probability distribution. «A» is an array of outcomes, and «P» is the corresponding array of probabilities. «A» and «P» must both be indexed by «I».&lt;br /&gt;
&lt;br /&gt;
== When to Use ==&lt;br /&gt;
&lt;br /&gt;
Use [[ChanceDist]]() instead of the probability table when:&lt;br /&gt;
* The array of outcomes «A» is multidimensional, or&lt;br /&gt;
* The outcomes and probabilities arrays are defined as other Variables; the Variables can be used in other parts of your model.&lt;br /&gt;
&lt;br /&gt;
As of build 4.0.0.51, [[ChanceDist]] cannot be used within [[Random]].  This enhancement may occur in future releases.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;Index Index_b := [Red, White, Blue]&amp;lt;/code&amp;gt;&lt;br /&gt;
:&amp;lt;code&amp;gt; Variable Array_1 :=&amp;lt;/code&amp;gt;&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; | Index_b &amp;amp;#9654; &lt;br /&gt;
|-&lt;br /&gt;
! Red !! White !! Blue&lt;br /&gt;
|-&lt;br /&gt;
| 0.3 || 0.2 || 0.5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Mid Value ==&lt;br /&gt;
&lt;br /&gt;
[[ChanceDist]] is a discrete distribution, and as such it assumes that the data points in «A» are categorical (discrete).  It also assumes that the ordering for the points is the ordering given in «A».  Thus, the [[Mid]] value returns the middle point along the ordering given by «A» (where the position of the middle point is based on the weightings of each point in «P»).  &lt;br /&gt;
&lt;br /&gt;
When «A» consists of unordered numeric points, this can be confusing, since the [[Mid]] value isn't the same as the numeric median.  For example, with &amp;lt;code&amp;gt;P = 1/5 and&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;A = [9, 3, 1, 8, 7]&amp;lt;/code&amp;gt;, the [[Mid]] value is 1.&lt;br /&gt;
&lt;br /&gt;
Even when the points in «A» are ordered and numeric, [[Mid]] is not the same as the continuous median when the number of points is even.  For example, &amp;lt;code&amp;gt;P = 1/4&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;A = [1, 2, 3, 4]&amp;lt;/code&amp;gt; would return &amp;lt;code&amp;gt;Mid = 3&amp;lt;/code&amp;gt; even though &amp;lt;code&amp;gt;Median = 2.5&amp;lt;/code&amp;gt;.  The discrete median is always a point in the domain, hence must be one of the points in «A».&lt;br /&gt;
&lt;br /&gt;
In general in Analytica, [[Mid]] returns the median for a distribution.  This is still the case even in cases just mentioned as long as you realize that [[ChanceDist]] returns the categorical median, which is different from the continuous median.  For example, if you define &amp;lt;code&amp;gt;X := ChanceDist(P, A)&amp;lt;/code&amp;gt;, where «A» is an index, and set the domain of «X» to be an index domain based on «A», then the statistics result view for «X» will display the categorical median which will coincide with the [[Mid]] value for «X». The index-valued domain tells Analytica that «X» is discrete with a defined element ordering given by «A».&lt;br /&gt;
&lt;br /&gt;
When you are really dealing with a continuous quantity, you should be using either [[ProbDist]] or [[CumDist]] to define the distribution.  If you really want to re-sample from «A», but want [[Mid]] to return the &amp;quot;numerically-middle&amp;quot; sample, then use (for uniform «P»):&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;ChanceDist(1/Size(I), Sort(A, I), I)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or for non-uniform P:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;Var order := SortIndex(A, I) Do ChanceDist(P[I = order], A[I = order], I)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[ProbTable]]&lt;br /&gt;
* [[Uniform]]&lt;br /&gt;
* [[Prob_ChanceDist]]&lt;br /&gt;
* [[Custom discrete probabilities]]&lt;br /&gt;
* [[Distribution Densities Library]]&lt;/div&gt;</summary>
		<author><name>HEshraghi</name></author>
	</entry>
</feed>