python - Is there a pythonic idiom for changing the normal flow of execution based on a percentage? -


Edit - I am creating a data generator which allows users to specify specific fields as optional And the percentage fields do not return any returns instead of one option if the field is optional In other words, most of the time functions will return the priority value, but if the user wants this function, then without any abnormal form Some returns according to Rtist, then he can do it.

Currently:

  import random def foo (Val, PCT): Return Values ​​if random.random () & lt; 

class = "post-text" itemprop = "Text">

You can use a decorator, especially if you need to do this for a group of functions

  def sometimes (pct): def wrapper ( FN): Def F (* Args, ** kW): Return FN (* Elgs, ** KW) if random Random () & gt; PTT Any other returns F returns cover sometimes (PPT = 0.3) def foo (val): return value  

Comments

Popular posts from this blog

mysql - How to enter php data into a html multiple select box -

java - Can't add JTree to JPanel of a JInternalFrame -

c++ - Cassandra datastax cpp driver - avoiding unnecessary copies -