Splunk Dev

Is there a function that randomly shuffles results?

davidch12
Explorer

Similar to sort, except I'm looking for a function to randomly shuffle the results. This achieves the same result as the Linux shuf command.

Tags (1)
0 Karma

kelstahl8705
Path Finder

I have to look up this command every few months because I can never remember it... Are you talking about the 'scrub' command? Turns your search results from

email= thisemail@gmail.com  > email= fjnwspfvj@gmail.com or possibly to >
email= dspehbpwn@smrls.dpo    

It keeps the data in the same format just jumbles everything up?

https://docs.splunk.com/Documentation/SplunkCloud/9.2.2403/SearchReference/Scrub
https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Scrub


0 Karma

woodcock
Esteemed Legend

Like this:

 ... | eval _random=random()
 | sort 0 _random

Or this:

 ... | eval _random=md5(_raw)
 | sort 0 _random

davidch12
Explorer

Looks like the "0" argument to sort ensures all results are returned, even if the number is greater than 10,000:
https://docs.splunk.com/Documentation/Splunk/7.2.5/SearchReference/Sort

Is my interpretation correct?

0 Karma

woodcock
Esteemed Legend

Yes, this is very important; never run sort without a number.

0 Karma

martinpu
Communicator

Hi,

how about something like this?

index=yourIndex
| eval randomValue=random()
| sort randomValue
| table _time _raw randomValue
Get Updates on the Splunk Community!

Meet Duke Cyberwalker | A hero’s journey with Splunk

We like to say, the lightsaber is to Luke as Splunk is to Duke. Curious yet? Then read Eric Fusilero’s latest ...

The Future of Splunk Search is Here - See What’s New!

We’re excited to introduce two powerful new search features, now generally available for Splunk Cloud Platform ...

Splunk is Nurturing Tomorrow’s Cybersecurity Leaders Today

Meet Carol Wright. She leads the Splunk Academic Alliance program at Splunk. The Splunk Academic Alliance ...