core.utils.random

View Source
import random, time

class Random():

	_RANDOM_SEED = int(time.time() * 1000)

	def set_seed(seed):
		'''
			Set the global Random seed! (do only once per run and before creating any objects!)
			Else will use scripts init time
		'''
		Random._RANDOM_SEED = seed

	def get_seed():
		'''
			Get the currently used seed
		'''
		return Random._RANDOM_SEED

	def get_generator():
		'''
			Get a seeded fresh Python Random object (always use this in the entire project to get randomness 
			or act based on value of seed, e.g. as random index for initialization)
		'''
		return random.Random(Random._RANDOM_SEED)

	def strip_seed(cachename):
		'''
			Classes like Corpus, Annotator and AnnotatedCorpus add the used seed to their cachename,
			one may strip it from a returned cachename using this function.

			``strip_seed(foo.get_cachename())``returns same name, but no values of seed
			
			(see also `core.utils.functions.strip_all`)
		'''
		return cachename.replace('_' + str(Random.get_seed()) + '_', '').replace('-' + str(Random.get_seed()) + '_', '_')
	
#   class Random:
View Source
class Random():

	_RANDOM_SEED = int(time.time() * 1000)

	def set_seed(seed):
		'''
			Set the global Random seed! (do only once per run and before creating any objects!)
			Else will use scripts init time
		'''
		Random._RANDOM_SEED = seed

	def get_seed():
		'''
			Get the currently used seed
		'''
		return Random._RANDOM_SEED

	def get_generator():
		'''
			Get a seeded fresh Python Random object (always use this in the entire project to get randomness 
			or act based on value of seed, e.g. as random index for initialization)
		'''
		return random.Random(Random._RANDOM_SEED)

	def strip_seed(cachename):
		'''
			Classes like Corpus, Annotator and AnnotatedCorpus add the used seed to their cachename,
			one may strip it from a returned cachename using this function.

			``strip_seed(foo.get_cachename())``returns same name, but no values of seed
			
			(see also `core.utils.functions.strip_all`)
		'''
		return cachename.replace('_' + str(Random.get_seed()) + '_', '').replace('-' + str(Random.get_seed()) + '_', '_')
#   Random()
#   def set_seed(seed):
View Source
	def set_seed(seed):
		'''
			Set the global Random seed! (do only once per run and before creating any objects!)
			Else will use scripts init time
		'''
		Random._RANDOM_SEED = seed

Set the global Random seed! (do only once per run and before creating any objects!) Else will use scripts init time

#   def get_seed():
View Source
	def get_seed():
		'''
			Get the currently used seed
		'''
		return Random._RANDOM_SEED

Get the currently used seed

#   def get_generator():
View Source
	def get_generator():
		'''
			Get a seeded fresh Python Random object (always use this in the entire project to get randomness 
			or act based on value of seed, e.g. as random index for initialization)
		'''
		return random.Random(Random._RANDOM_SEED)

Get a seeded fresh Python Random object (always use this in the entire project to get randomness or act based on value of seed, e.g. as random index for initialization)

#   def strip_seed(cachename):
View Source
	def strip_seed(cachename):
		'''
			Classes like Corpus, Annotator and AnnotatedCorpus add the used seed to their cachename,
			one may strip it from a returned cachename using this function.

			``strip_seed(foo.get_cachename())``returns same name, but no values of seed
			
			(see also `core.utils.functions.strip_all`)
		'''
		return cachename.replace('_' + str(Random.get_seed()) + '_', '').replace('-' + str(Random.get_seed()) + '_', '_')

Classes like Corpus, Annotator and AnnotatedCorpus add the used seed to their cachename, one may strip it from a returned cachename using this function.

strip_seed(foo.get_cachename())returns same name, but no values of seed

(see also core.utils.functions.strip_all)