Splunk Search

using spl to pick random names from list

PaulaCom
Path Finder

Morning All 

I am trying to work out how to use splunk spl to pick random names from a list

i have 1 field called 'displayName'. there are over 200 entries and i'd like to use Splunk to pick 5 random names 

 

appreciate help in this

Paula  

 

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

If your values are in a multi-value field, you can do something like this

| eval choice=mvindex(displayName, random()%200)

If the names are in separate events, you could do something like this

| eval id=random()%500
| sort 0 id
| head 5

View solution in original post

PaulaCom
Path Finder

thank  you the second option works for what i need

 

0 Karma

PaulaCom
Path Finder

i've looked at similar search online and have come up with this

| table "Display Name"
| eval "group" = (random() % 2) +1
| stats list("Display Name") as "Display Name" by "group"

this is returning random names in two groups
      

group display Name
1

joe blogs 5

joe blogs 2

joe blogs  6

2

joe blogs 7

joe blogs 8

joe blogs  12

 

Any ideas how i can set the number returning for each group? maybe using the limit function???

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval id=random()
| sort 0 id
| streamstats count as id
| eval group=((id - 1)%5) + 1
| stats list("Display Name") as "Display Name" by group

ITWhisperer
SplunkTrust
SplunkTrust

If your values are in a multi-value field, you can do something like this

| eval choice=mvindex(displayName, random()%200)

If the names are in separate events, you could do something like this

| eval id=random()%500
| sort 0 id
| head 5
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...