Sponsored Content
Full Discussion: generate random base 16
Top Forums Shell Programming and Scripting generate random base 16 Post 302702757 by Chubler_XL on Tuesday 18th of September 2012 08:33:26 PM
Old 09-18-2012
Using bash internals exclusively you can:

Code:
printf "%04x" $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM

edit: oops range of RANDOM is only 0 - 32767; adjusted answer below (not quite so nice)

Code:
for ((i=0;i<10;i++)) {
   printf "%03x" $((RANDOM%4096))
} ; printf "%02x" $((RANDOM%256))

or

Code:
printf "%03x%03x%03x%03x%03x%03x%03x%03x%03x%03x%02x" \
    $((RANDOM%4096)) $((RANDOM%4096)) \
    $((RANDOM%4096)) $((RANDOM%4096)) \
    $((RANDOM%4096)) $((RANDOM%4096)) \
    $((RANDOM%4096)) $((RANDOM%4096)) \
    $((RANDOM%4096)) $((RANDOM%4096)) \
    $((RANDOM%256))


Last edited by Chubler_XL; 09-18-2012 at 10:02 PM..
 

10 More Discussions You Might Find Interesting

1. Programming

How to generate a random number?

How to generate a random integer with specific range(for example, from 1 to 1000)? Also, how to convert a floating point number into a integer? (2 Replies)
Discussion started by: MacMonster
2 Replies

2. Shell Programming and Scripting

Generate a random password

Hello All... Can someone help me generate a random password which will be 7 characters long which contains alpha-numeric characters using shell script. I am looking to store the output of the script that generates the password to a variable within a script and use it as the password. ... (5 Replies)
Discussion started by: chiru_h
5 Replies

3. Shell Programming and Scripting

generate random number in perl

Could any one tell how can I generate random number from (0, 100..200) in perl? Thanks! (2 Replies)
Discussion started by: zx1106
2 Replies

4. Programming

Generate Random Password in C

I need a function to generate a random alphanumeric password in C code. It needs to be between 6-8 characters and follow the following rules: Reject if same char appears # time: 4 or more Reject if same char appears consecutively: 3 or more I have the following random password working for... (2 Replies)
Discussion started by: vjaws
2 Replies

5. Shell Programming and Scripting

How to generate random strings from regx?

Hi, Guz! I'm working on a scripts compiler which needs a function to generate random strings. I think REGX may be a good solution to restrict the string format. Before DIYing I'd like asking for any existing libs or codes. Any help will be appreciated! (7 Replies)
Discussion started by: wqqafnd
7 Replies

6. Programming

Generate random number

I saw this formula to generate random number between two specified values in shell script.the following. $(((RANDOM%(max-min+divisibleBy))/divisibleBy*divisibleBy+min)) Give a example in book. Generate random number between 6 and 30.like this. $(((RANDOM%30/3+1)*3)) But I have a... (1 Reply)
Discussion started by: luoluo
1 Replies

7. Programming

generate array of random numbers

hi guys, I am writing a c program that generates a two dimensional array to make matrix and a vector of random numbers and perform multiplication. I can't figure out whats wrong with my code. It generates a matrix of random numbers but all the numbers in the vector array is same and so is the... (2 Replies)
Discussion started by: saboture88
2 Replies

8. Shell Programming and Scripting

Generate random numbers in script

i want to generate a random number through a script, and even if anyone reads the script, they wont be able to figure out what the random number is. only the person who setup the script would know it. something like this could work: random the full thread is here: ... (13 Replies)
Discussion started by: SkySmart
13 Replies

9. Shell Programming and Scripting

Need to generate a file with random data. /dev/[u]random doesn't exist.

Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom. I create a named pipe then: dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024 but when I cat a file to the fifo that's 1024 random bytes: cat randomfile.txt >... (7 Replies)
Discussion started by: Devyn
7 Replies

10. Shell Programming and Scripting

Help with generate a pair of random number

Hi, Is anybody experience generate a pair of random number by using awk command? I wanna to generate a pair of random number (range from 1 to 4124) and repeats it 416 times. Desired output 2 326 123 1256 341 14 3245 645 . . . I did write the below command: awk... (5 Replies)
Discussion started by: perl_beginner
5 Replies
BSD::arc4random(3pm)					User Contributed Perl Documentation				      BSD::arc4random(3pm)

NAME
BSD::arc4random - Perl interface to the arc4 random number generator SYNOPSIS
use BSD::arc4random qw(:all); $v = arc4random(); $v = arc4random_uniform($hz); if (!BSD::arc4random::have_kintf()) { $v = arc4random_addrandom("entropy to pass to the system"); } else { $v = arc4random_pushb("entropy to pass to the system"); $v = arc4random_pushk("entropy to pass to the kernel"); } $s = arc4random_bytes(16, "entropy to pass to libc"); arc4random_stir(); $s = arc4random_bytes(16); print $RANDOM; DESCRIPTION
This set of functions maps the arc4random(3) family of libc functions into Perl code. All functions listed below are ithreads-safe. The internal XS functions are not, but you are not supposed to call them, either. On module load, perl's internal PRNG is re-seeded, as a bonus, using srand with an argument calculated from using arc4random_pushb on some entropy returned from rand's previous state. LOW-LEVEL FUNCTIONS arc4random() This function returns an unsigned 32-bit integer random value. arc4random_addrandom(pbuf) This function adds the entropy from pbuf into the libc pool and returns an unsigned 32-bit integer random value from it. arc4random_pushb(pbuf) This function first pushes the pbuf argument to the kernel if possible, then the entropy returned by the kernel into the libc pool, then returns an unsigned 32-bit integer random value from it. arc4random_pushk(pbuf) This function first pushes the pbuf argument to the kernel if possible, then returns an unsigned 32-bit integer random value from the kernel. This function is deprecated. Use arc4random_pushb instead. arc4random_stir() This procedure attempts to retrieve new entropy from the kernel and add it to the libc pool. Usually, this means you must have access to the urandom(4) device; create it inside chroot(2) jails first if you use them. have_kintf() This constant function returns 1 if arc4random_pushb and/or arc4random_pushk actually call the kernel interfaces, 0 if they merely map to arc4random_addrandom instead. HIGH-LEVEL FUNCTIONS arc4random_bytes(num[, pbuf]) This function returns a string containing as many random bytes as requested by the integral argument num. An optional pbuf argument is passed to the system first. arc4random_uniform(upper_bound) Calculate a uniformly distributed random number less than upper_bound avoiding "modulo bias". PACKAGE VARIABLES $RANDOM The $RANDOM returns a random value in the range [0; 32767] on each read attempt and pushes any value it is assigned to the kernel. It is tied at module load time. tie variable, 'BSD::arc4random'[, max] You can tie any scalar variable to this package; the max argument is the maximum number returned; if undefined, 0 or >= 0xFFFFFFFF, no bound is used, and values in the range [0; 2**32-1] are returned. They will behave like $RANDOM. AUTHOR
Thorsten Glaser <tg@mirbsd.de> SEE ALSO
The arc4random(3) manual page, available online at: <https://www.mirbsd.org/man/arc4random.3> Perl's rand and srand functions via perlfunc and perlfaq4. The randex.pl plugin for Irssi, implementing the MirOS RANDEX protocol (entropy exchange over IRC), with CVSweb at: <http://cvs.mirbsd.de/ports/net/irssi/files/randex.pl> <https://www.mirbsd.org/a4rp5bsd.htm> when it's done being written. COPYRIGHT AND LICENSE
Copyright (c) 2008, 2009, 2010, 2011 Thorsten "mirabilos" Glaser Copyright (c) 2009 Benny Siegert Credits to Sebastian "Vutral" Schwarz This module is covered by the MirOS Licence: http://mirbsd.de/MirOS-Licence <http://mirbsd.de/MirOS-Licence> The original C implementation of arc4random_uniform was contributed by Damien Miller from OpenBSD, with simplifications by Jinmei Tatuya. perl v5.14.2 2011-06-05 BSD::arc4random(3pm)
All times are GMT -4. The time now is 02:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy