gen



Random generators

(should probably rename this to rand)

Schema

github.com/hofstadter.io/hof/flow/tasks/gen

package gen

// Seed the Range
Seed: {
	@task(gen.Seed)
	$task: "gen.Seed"

	// only set to ensure consistent output while testing 
	seed?: int // defaults to time.Now()
}

Int: {
	@task(gen.Int)
	$task: "gen.Int"
	max?:  int // max value if set

	// the random val returned
	val: int
}

Str: {
	@task(gen.Str)
	$task: "gen.Str"

	// number of runes to generate
	n: int | *12

	// possible runes, defaults to [a-zA-Z]
	runes?: string
}

// the other tasks don't really have schema or input

// c: string @task(gen.CUID)  // like UUID, but for cloud
// f: float  @task(gen.Float)
// n: float  @task(gen.Norm)
// n: string @task(gen.Now)   // RFC-3339
// s: string @task(gen.Slug)  // related to CUID
// u: string @task(gen.UUID)

Example

random example

exec hof flow ./in.cue

-- in.cue --
import "encoding/json"

@flow()

// seed with int value
seed: { seed: 0, done: _ } @task(gen.Seed)

gen: {
  t: { _, #dep: seed.done } @task(gen.Now)
  i: { _, #dep: seed.done } @task(gen.Int)
  s: { _, #dep: seed.done } @task(gen.Str)
  f: { _, #dep: seed.done } @task(gen.Float)
  n: { _, #dep: seed.done } @task(gen.Norm)
  u: { _, #dep: seed.done } @task(gen.UUID)
  c: { _, #dep: seed.done } @task(gen.CUID)
  g: { _, #dep: seed.done } @task(gen.Slug)
}

print: { 
  @task(os.Stdout)
  dep: { for k,v in gen { (k): v } } 
  s: json.Indent(json.Marshal(dep), "", "  ")
  text: s + "\n"
}
2022 Hofstadter, Inc