Header Shadow Image


RANDOM numbers in ksh or ksh93

Here's are an example of a random number generator in KSH or it's newer counterpart KSH93.  For this post, we'll use the latest KSH from AT&T Labs:

  • Generate a random set of integers between 0 – 256 and use them to create a random set of IP type entries:

#!/bin/ksh93u+

for (( KEY=0; KEY < 1000000000; KEY++ )); do
    print $(( RANDOM / 128 ))"."$(( RANDOM / 128 ))"."$(( RANDO^C/ 128 ))"."$(( RANDOM / 128 ));
done


The purpose of the above is to obtain a random set of entries (IP like) for testing purposes in other logic including testing regular expressions.  RANDOM, in this case generates a number between 0 and 32768 and when divided by 128, will print out the intiger part of the equation.  To assign a random number a statement similar to MVAR=$RANDOM; can also be used.

Cheers,
TK

Subscribe
Notify of
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

     
  Copyright © 2003 - 2025 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License

 

0
Would love your thoughts, please comment.x
()
x
The IT Development and Technology Mini Vault | MicroDevSys.com
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.