Records with Random Chance of Loss

A new Record is created every 3 reloads of this page.   There is a 10% chance per reload for each Record to obtain a new Chance-of-loss Attribute.   There are 3 unique Attributes: Small (20%), Medium (50%), and Large (80%).   The percent Chance-of-loss is applied to a base 25% chance of loss per reload per Attribute.   Effectively, a Record with only a Small chance of loss Attribute would have a 5% chance to be lost per reload (20% * 25%).   A Record with all 3 Attributes would have 3 independent chances to be lost per reload: 5%, 12.5%, and 20%.   The Activity panel is styled using Bootstrap 3 default theme classes.  

Records that survived the reload, and were not lost, are highlighted in green.   Messages about Records are highlighted in yellow.   Records that are lost are highlighted in red



Processed this Hashtag Markup:
<div class="panel panel-primary" id="activity">
	<div class="panel-heading">
		<h4 class="panel-title text-center">Random Chance Activity</h4>
	</div>
	<table class="table table-condensed text-center">

<# start list for chance_records;
	include when status is "active";
	relate id to chance_record_attributes.record_id;
	relate chance_record_attributes.attribute_id to chance_attributes.id;
	sort by counter descending as number, id, chance_attributes.loss_percent as number;
#>
	<#: process each record attribute, and apply a chance of record loss :#>
	<# set chance_attributes_list to ""; #>
	<# set record_labels to ""; #>
	<# start row loop for chance_records.id; #>
		<# set record_loss_percent to (<# chance_attributes.loss_percent as number #> / 100) * 25; #>
		<# start chance of <# record_loss_percent #>% #>
			<# update record for "<# chance_records.id #>";
				set status to "lost";
				set loss_cause to "<# chance_attributes.name #>";
			#>
			<tr>
				<td class="alert alert-danger">
					<b>Record #<# chance_records.instance_id #></b> was lost.&nbsp; 
					Cause Attribute: 
					<span class="label label-danger"><# chance_records.loss_cause as html #></span>&nbsp;
					Final counter: <b><# chance_records.counter as integer #></b>.
				</td>
			</tr>
			<# break to next row; #>
		<# end chance #>
		<# append chance_attributes_list with "<# chance_attributes.id #>" using ","; #>
		<# append record_labels with """
			<span class="label label-danger"><# chance_attributes.name as html #></span>
		"""; #>
	<# end row loop #>

	<#: chance record wasn't lost... increment the reload counter :#>
	<# update record for "<# chance_records.id #>";
		increment counter by 1;
	#>
	<tr>
		<td class="alert alert-success">
			<b>Record #<# chance_records.instance_id #></b> <# record_labels #> was not lost.&nbsp;
			Reload counter: <b><# chance_records.counter as integer #></b>.
		</td>
	</tr>

	<#: apply chance of record obtaining a new random chance of loss attribute :#>
	<# start chance of 10% #>
		<# set new_attribute_id to random chance_attributes.id not in "<# chance_attributes_list #>"; #>
		<# if "<# new_attribute_id #>"!="" #>
			<# create record for "chance_record_attributes"; 
				set record_id to "<# chance_records.id #>";
				set attribute_id to "<# new_attribute_id #>";
			#>
			<# apply chance_attributes.<# new_attribute_id #> as "new_attribute"; #>
			<tr>
				<td class="alert alert-warning">
					<b>Record #<# chance_records.instance_id #></b> got a new 
					<span class="label label-danger"><# new_attribute.name as html #></span>
					chance of loss Attribute.
				</td>
			</tr>
		<# end if #>
	<# end chance #>

<# end list #>

<#: process countdown for new chance record creation :#>
<# if "<#[session.chance_countdown as integer]#>"<="1" #>
	<#: countdown complete!  create new chance record, and reset the countdown :#>
	<# create record for "chance_records" as "new_record";
		set status to "active";
	#>
	<# set session.chance_countdown to 3; #>
	<tr>
		<td class="alert-success">
			New Chance Record!&nbsp; Welcome, <b>Record #<#[new_record.instance_id]#></b>
		</td>
	</tr>
	<tr>
		<td class="alert-warning">
			Only <b><#[session.chance_countdown as plural "more reload|more reloads"]#></b> 
			until another Chance Record is created.
		</td>
	</tr>
<# else #>
	<# decrement session.chance_countdown by 1; #>
	<tr>
		<td class="alert-warning">
			Only <b><#[session.chance_countdown as plural "more reload|more reloads"]#></b> 
			until a new Chance Record is created.
		</td>
	</tr>
<# end if #>

	</table>
</div>

The Random Chance Mini-App uses Hashtag Markup to demonstrate an arbitrary non‑deterministic process.

Records are created on a reload count schedule, and randomly obtain negative attributes that can lead to the record being flagged as lost.

All records are stored in an SQL Database.