public static double fst_sample(Intarray result, IGenericFst fst, int max=1000)
{
double total_cost = 0;
int current = fst.GetStart();
for (int counter = 0; counter < max; counter++)
{
Intarray inputs = new Intarray();
Intarray outputs = new Intarray();
Intarray targets = new Intarray();
Floatarray costs = new Floatarray();
fst.Arcs(inputs, targets, outputs, costs, current);
// now we need to deal with the costs uniformly, so:
costs.Push(fst.GetAcceptCost(current));
int choice = sample_by_costs(costs);
if (choice == costs.Length() - 1)
break;
result.Push(outputs[choice]);
total_cost += costs[choice];
current = targets[choice];
}
return total_cost + fst.GetAcceptCost(current);
}