Over a million developers have joined DZone.

generate random string from a canonical form useful for responding like humans



#!/usr/bin/env ruby
# generate a single sentence from a canonical form
# canonical sentence is a multi sentences combined in one
# form, generator will generate a sentence from it randomly
# based on the form, for example:
# "Hello [Emad|Elsaid]" , may generate "Hello Emad" or
# "Hello Elsaid" the result is random.
# also you could nest [] inside each other to gain a multi level
# canonical sentence example:
# "[[Hi|Hello] [Emad|elsaid] | good [morning|night] sir]"
def generate(result)
	while result.include? '[' 
		s_start = result.index '['
		s_end = s_start+1
		while s_end

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}