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
Get Updates on the Splunk Community!

New Year. New Skills. New Course Releases from Splunk Education

A new year often inspires reflection—and reinvention. Whether your goals include strengthening your security ...

Splunk and TLS: It doesn't have to be too hard

Overview Creating a TLS cert for Splunk usage is pretty much standard openssl.  To make life better, use an ...

Faster Insights with AI, Streamlined Cloud-Native Operations, and More New Lantern ...

Splunk Lantern is a Splunk customer success center that provides practical guidance from Splunk experts on key ...