Sponsored Content
Top Forums UNIX for Dummies Questions & Answers A crude random byte generator... Post 302855865 by wisecracker on Saturday 21st of September 2013 08:18:23 AM
Old 09-21-2013
Hi figaro...
Quote:
The quality of the output of the algorithm is also very sensitive to the value of seed (line 10).
I was well aware of this that is why I used a variable instead of a fixed value inside line 25.
The idea was to use the last byte read as the next "seed" but I didn't pursue it any further. "seed" must always
have a value greater than or equal to 1 and less than or equal to decimal value 256 added to the current byte in use.
(I assumed you guys would see the flaw and correct as you need.)
However if the current byte value would be zero then "seed" would have to be a minimum value of "1".
(This is taken care of with the limitation of fixing "seed" in the script shown.)
Not because of anything to do with binary zero in shell scripting per-se but it would just stop there until the
loop finished and give that character value at that point continuously ( <- if that sentence is lucid enough. ).

Bazza...

EDIT: Made more lucid.

This is a simple way of making it a little better without the complexity of storing the previous and current
bytes read. (Line 26.)
Code:
if [ $subscript -ge $file_size ]; then subscript=$[ ( $dec_value + 9999 ) ]; fi


Last edited by wisecracker; 09-21-2013 at 06:27 PM.. Reason: Rewrite to make more lucid...
 

9 More Discussions You Might Find Interesting

1. Solaris

Does Solaris have a random number generator?

I am trying to find a way to generate random numbers within a shell script. Does Solaris have a utility that will generate random numbers? Thanks in advance. B (3 Replies)
Discussion started by: one_ring99
3 Replies

2. Shell Programming and Scripting

Check if 2 files are identical byte-to-byte?

In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server. For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match. Please... (4 Replies)
Discussion started by: krishmaths
4 Replies

3. Shell Programming and Scripting

Random Sentence Generator

Hi, I need to create a table with random sentences. I need lines that are upto 1000 characters in lenght. I need a random sentence generator that will create sentences and output it to a text file. The sentences should be of lenght varying from 1 to 1000. Does anyone know how this can be... (7 Replies)
Discussion started by: kaushys
7 Replies

4. Shell Programming and Scripting

Need specialized random string generator script

Hi, I need a script that will generate a set of random strings in sequence, with the ability to predetermine the length, quantity, and alphabet of individual string, and to use the outputs of earlier strings in the sequence to define the parameters of later strings. For examples, I might want... (5 Replies)
Discussion started by: vajrajames
5 Replies

5. Shell Programming and Scripting

Grab exactly one byte from a FIFO, at random intervals

I want to develop a script of the following form: #!/bin/bash # Function 'listen' opens a data stream # which stores all incoming bytes in # a buffer, preparing them to be # grabbed by a following function # which appears at random # intervals during the execution of # the script ... (11 Replies)
Discussion started by: vomv1988
11 Replies

6. Shell Programming and Scripting

A Crude 1KHz Audio Sinewave Generator Demo...

A very simple crude sinewave generator. The file required is generated inside the code, is linear interpolated and requires /dev/audio to work. Ensure you have this device, if not the download oss-compat from your OS's repository... It lasts for about 8 seconds before exiting and saves a... (5 Replies)
Discussion started by: wisecracker
5 Replies

7. UNIX for Dummies Questions & Answers

Changing a special line and Byte in a random file

Hello I created 3 files by: dd if=/dev/urandom bs=1024 count=1000000 of=./testfile1 dd if=/dev/urandom bs=1024 count=5000000 of=./testfile2 dd if=/dev/urandom bs=1024 count=10000000 of=./testfile3 Now I want to know how to make a change in a specific byte and/or line of theses files? (2 Replies)
Discussion started by: frhling
2 Replies

8. Shell Programming and Scripting

awk (or) UNIX random RGB colors generator?

Dear UNIX Friends, I was wondering if there is a random RGB color generator or any function in any unix platforms. Please share your ideas. Thanks (2 Replies)
Discussion started by: jacobs.smith
2 Replies

9. Shell Programming and Scripting

Random Password generator with 2 digits and 6 characters

I am using the below to random generate a password but I need to have 2 numeric characters and 6 alphabetic chars head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8 ; echo '' 6USUvqRB ------ Post updated at 04:43 PM ------ Any Help folks - Can the output be passed onto a sed command to... (9 Replies)
Discussion started by: infernalhell
9 Replies
rand(3C)						   Standard C Library Functions 						  rand(3C)

NAME
rand, srand, rand_r - simple random-number generator SYNOPSIS
#include <stdlib.h> int rand(void); void srand(unsigned int seed); int rand_r(unsigned int *seed); DESCRIPTION
The rand() function uses a multiplicative congruential random-number generator with period 2^32 that returns successive pseudo-random num- bers in the range of 0 to RAND_MAX (defined in <stdlib.h>). The srand() function uses the argument seed as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand(). If srand() is then called with the same seed value, the sequence of pseudo-random numbers will be repeated. If rand() is called before any calls to srand() have been made, the same sequence will be generated as when srand() is first called with a seed value of 1. The rand_r() function has the same functionality as rand() except that a pointer to a seed seed must be supplied by the caller. If rand_r() is called with the same initial value for the object pointed to by seed and that object is not modified between successive calls to rand_r(), the same sequence as that produced by calls to rand() will be generated. The rand() and srand() functions provide per-process pseudo-random streams shared by all threads. The same effect can be achieved if all threads call rand_r() with a pointer to the same seed object. The rand_r() function allows a thread to generate a private pseudo-random stream by having the seed object be private to the thread. USAGE
The spectral properties of rand() are limited. The drand48(3C) function provides a better, more elaborate random-number generator. When compiling multithreaded applications, the _REENTRANT flag must be defined on the compile line. This flag should be used only in mul- tithreaded applications. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
drand48(3C), attributes(5), standards(5) SunOS 5.11 19 May 2004 rand(3C)
All times are GMT -4. The time now is 01:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy