Splunk Search

Eval random function.

Substance82
Path Finder

How do I format a returned int into a phone number with the hyphen using the eval random function. 

 

What I have so far: 

| eval PhoneNumber = (random() )

Labels (1)
Tags (1)
0 Karma

Substance82
Path Finder

Thanks for the reply. I actually need a 7 digit format like " 555-XXXX". 

0 Karma

Substance82
Path Finder

where the last 4 digits contain any number from 0 to 9

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The random function only returns an integer and there is no way to force it to include hyphens in the output.

Since the function may return an integer too small for a phone number, I suggest using multiple calls to build it.  Here's an example using the North American Numbering Plan.

 

 

| eval PhoneNumber = (random() % 1000)."-".(random() % 1000)."-".(random() % 10000)

 

 

Additional massaging may be needed if you want more realistic phone numbers (no "001" for an area code, for example).

---
If this reply helps you, Karma would be appreciated.

ITWhisperer
SplunkTrust
SplunkTrust

It depends on the format of phone number that you want and any range constraints on the number.

Essentially, random() returns a "random" potentially large integer. This is usually reduced in range by using a modulus operation. e.g. 

| eval number=random() % 1000000

This will give you an integer below a million. Alternatively, you could randomise parts of the number e.g.

| eval number = "1-".printf("%0.3d", random() % 1000)."-".printf("%04d", random() %10000)
0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...