What You’ll Learn in This Module

The Avatar Name Generator is a clever snippet pattern that produces human-sounding first names for demos, persona-based presentations, or any situation where you want a realistic name without using real contact data. The same contact always gets the same name within a given day, but the name rotates day-to-day — providing variety without randomness.

📖 https://school.cast.app/liquid/liquid-library.html#avatar-name-generators


Why This Pattern Matters

There are several situations where you need a realistic name but can’t (or shouldn’t) use the real contact’s name:

  • Demo environments: Showing prospects how Cast works without revealing real customer data
  • Persona-based presentations: “Here’s what Sarah from your team accomplished this week”
  • Privacy-conscious scenarios: Internal reviews where contact names should be anonymized
  • Template previews: Testing narrations before CRM data is connected

Hard-coding a name like “Jane” works but feels robotic. The Avatar Generator picks from a diverse list of names, giving each contact a consistent name that feels natural.


How It Works — The Algorithm

The generator uses three ingredients:

  1. A list of names — 26 names, split into an array
  2. The day of the week — a number from 0 (Sunday) to 6 (Saturday)
  3. The contact ID — a unique number for each contact

The algorithm:


nameIndex = (contact_id × day_of_week) modulo number_of_names

Analogy: Imagine spinning a wheel with 26 names on it. The contact ID determines how many notches you spin, and the day of the week adds a daily twist. The same contact on the same day always lands on the same name — deterministic, not random.

Why modulo? The modulo operation (remainder after division) ensures the result always falls within the range 0–25, no matter how large the contact ID is. Contact ID 1,000,000 and contact ID 7 both produce a valid index.

Why include the day of week? Without it, the same contact would always get the same name. Including the day adds variety — the avatar “changes shifts” daily.


Female Avatar Snippet


{% comment %} Snippet Name: AvatarFemale {% endcomment %}
{% assign names = "Amy,Bella,Chloe,Diana,Emily,Fiona,Grace,Hannah,Ivy,Julia,Kayla,Lily,Madison,Natalie,Olivia,Pamela,Quinn,Rachel,Sophia,Taylor,Uma,Vivian,Willow,Xena,Yasmin,Zoe" | split: ',' %}

{% assign dow = "now" | date: "%w" | minus: 1 | modulo: 7 %}
{% assign contactId = contact_id | default: 1 %}
{% assign nameIndex = contactId | times: dow | modulo: names.size %}
{{ names[nameIndex] }}

Let’s trace through each line:

  1. names — 26 female names, split into an array
  2. dow — Day of week: "now" | date: "%w" returns 0–6 (Sunday=0). minus: 1 | modulo: 7 shifts the range (so Sunday becomes 6 instead of 0, avoiding multiplication by zero)
  3. contactId — The contact’s unique ID, with a fallback of 1 if missing
  4. nameIndex — Multiply contact ID by day of week, then modulo by array size to get a valid index (0–25)
  5. names[nameIndex] — Pick the name at that position

Male Avatar Snippet


{% comment %} Snippet Name: AvatarMale {% endcomment %}
{% assign names = "Adam,Brian,Charles,Daniel,Ethan,Frank,George,Henry,Isaac,Jack,Kevin,Liam,Michael,Nathan,Oliver,Peter,Quincy,Ryan,Samuel,Thomas,Uri,Victor,William,Xander,Yusuf,Zachary" | split: ',' %}

{% assign dow = "now" | date: "%w" | minus: 1 | modulo: 7 %}
{% assign contactId = contact_id | default: 1 %}
{% assign nameIndex = contactId | times: dow | modulo: names.size %}
{{ names[nameIndex] }}

The logic is identical — only the name list differs.


Using Avatars in Narrations

Once the snippets are created:


{{ AvatarFemale }} from your team just completed onboarding.


{{ AvatarMale }} submitted {{ AvatarMale | cast_apostrophe }} first report this week.

Wait — that second example has a problem. If you call the snippet twice, it runs the calculation twice and produces the same name, but using cast_apostrophe on the snippet output directly should work. A safer pattern:


{%- assign avatar = AvatarFemale | strip -%}
{{ avatar }} from your team just completed onboarding.
{{ avatar | cast_apostrophe }} first report was submitted on time.

By assigning the snippet result to a variable first, you ensure consistency and can apply filters cleanly.


Technique Module How It’s Used
split into array Module 6 Creating the name list from a string
date: "%w" Module 7 Getting the current day of week
modulo Module 5 Wrapping the index to stay within array bounds
times Module 5 Combining contact ID with day of week
Array index access [n] Module 6 Picking the name by position
default Module 4 Fallback for missing contact ID

Customizing the Pattern

Use your own name lists

Replace the 26 names with any set you prefer. The modulo: names.size automatically adapts to whatever array size you use:


{% assign names = "Aisha,Chen,Fatima,Ingrid,Keiko,Lina,Mei,Nadia,Olga,Priya" | split: ',' %}

With 10 names, modulo: names.size becomes modulo: 10.

Add more variation

You could use additional variables to increase variety:


{%- assign seed = contactId | times: dow | plus: names.size -%}
{%- assign nameIndex = seed | modulo: names.size -%}

Adding names.size as a constant offset shifts the selection pattern.

Use for company avatars

The same technique works for company names, cities, or any list:


{% assign companies = "Acme,Globex,Initech,Hooli,Pied Piper,Umbrella,Wayne,Stark" | split: ',' %}
{% assign companyIndex = contactId | times: dow | modulo: companies.size %}
{{ companies[companyIndex] }}


Common Mistakes

Not handling the case where contact_id is missing:


{% assign nameIndex = contact_id | times: dow | modulo: names.size %}

If contact_id is nil, the multiplication produces 0 — everyone gets the same name.

Default to a non-zero value:


{% assign contactId = contact_id | default: 1 %}


Calling the snippet multiple times expecting different names:


{{ AvatarFemale }} and {{ AvatarFemale }}

Both calls produce the same name (same contact, same day). This is by design — it’s deterministic.

If you need two different names, use both snippets:


{{ AvatarFemale }} and {{ AvatarMale }}


Try It Yourself

Exercise: Modify the avatar pattern to create a TeamRole snippet that assigns a random-feeling but deterministic role title (like “Product Manager,” “Engineering Lead,” “Solutions Architect,” “VP of Operations”) to each contact. Use a list of at least 6 roles.

Click to reveal the answer ```liquid {% comment %} Snippet Name: TeamRole {% endcomment %} {%- assign roles = "Product Manager,Engineering Lead,Solutions Architect,VP of Operations,Director of CS,Head of Analytics,Senior Consultant,Program Manager" | split: ',' -%} {%- assign dow = "now" | date: "%w" | minus: 1 | modulo: 7 -%} {%- assign contactId = contact_id | default: 1 | plus: 0 -%} {%- assign roleIndex = contactId | times: dow | modulo: roles.size -%} {{ roles[roleIndex] | strip }} ``` Usage in narration: ```liquid {%- assign avatar = AvatarFemale | strip -%} {%- assign role = TeamRole | strip -%} {{ avatar }}, your {{ role }}, completed 3 certifications this month. ``` Output: `Sophia, your Solutions Architect, completed 3 certifications this month.`

What’s Next

In Module 19, you’ll learn the Benchmarking and Gamification patterns — comparing a customer’s metrics against industry averages and generating dynamic, competitive commentary.


📖 Official documentation:

  • Snippet Library: https://school.cast.app/liquid/liquid-library.html#avatar-name-generators

This site uses Just the Docs, a documentation theme for Jekyll.