// Copyright 2005-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the 'License'); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an 'AS IS' BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef FST_TEST_RAND_FST_H_ #define FST_TEST_RAND_FST_H_ #include #include #include #include #include #include #include namespace fst { // Generates a random FST. template void RandFst(const int num_random_states, const int num_random_arcs, const int num_random_labels, const float acyclic_prob, Generate generate, uint64_t seed, MutableFst *fst) { using Label = typename Arc::Label; using StateId = typename Arc::StateId; using Weight = typename Arc::Weight; // Determines direction of the arcs wrt state numbering. This way we // can force acyclicity when desired. enum ArcDirection { ANY_DIRECTION = 0, FORWARD_DIRECTION = 1, REVERSE_DIRECTION = 2, NUM_DIRECTIONS = 3 }; std::mt19937_64 rand(seed); const StateId ns = std::uniform_int_distribution<>(0, num_random_states - 1)(rand); std::uniform_int_distribution arc_dist(0, num_random_arcs - 1); std::uniform_int_distribution