Splunk Search

conditionally using random()

abby_xr
Splunk Employee
Splunk Employee

Based on my dataset, I have 10 items in total and I wanna generate a new field randomly for each different item. 

E.g.:

basesearch

| eval new_field=case(
FieldA=item_1,(random() % 4) + 1,
FieldA=item_2,(random() % 4) + 1,
FieldA=item_3, (random() % 4) + 1,
......
FieldA=item_10, (random() % 4) + 1)

but the results of new_field for each item are different. what I want is the newfield_1 is fixed, for example,

"newfield_1=(random() % 4) + 1, if fiedA==item_1: FieldA=newfield_1 (newfield_1 won't change again)"

How can I keep consistent for the different items? Thank you for the help.

Labels (2)
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2026-2027 SplunkTrust is officially open. If ...