Sponsored Content
Top Forums UNIX for Advanced & Expert Users UNIX script for making random numbers without repetition Post 302849679 by Chubler_XL on Monday 2nd of September 2013 10:44:12 PM
Old 09-02-2013
OK my mistake, try this:

Code:
awk '
{ V[NR]=$1 }
END {
  srand()
  for(i=1;i<=1440;) {
    v=V[int(1+rand()*7200)]
    if (!(v in N)) {
       N[v]
       print v
       i++
    }
  }
}' random.txt

or even:
Code:
sort random.txt | uniq | shuf | head -1440

This User Gave Thanks to Chubler_XL For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Random numbers without repetition

Is anyone know some scripts to generate random number without repetition using bash; for example generate 10 different random numbers. Thanks (8 Replies)
Discussion started by: asal_email
8 Replies

2. Programming

How to set constrain on random numbers in c

Hi, I am currently trying to generate multiple random numbers in C for different variable:- die1=1+(rand()%5); die2=1+(rand()%5); die3=1+(rand()%5); die4=1+(rand()%5); But I need to contrain the total of die1, die2,die3 and die4 to be 5 as well. If i insert die1+die2+die3+die4=5, i do... (6 Replies)
Discussion started by: ahjiefreak
6 Replies

3. UNIX for Dummies Questions & Answers

Making UNIX script executable

Hello, I am very new to UNIX and I have been learning about writing scripts and making them executable. I created a script called myscript. It has three lines: #! /bin/sh # This is my first shell script echo friendsjustfriends Now I try to run it using the sh command and it works Next I... (4 Replies)
Discussion started by: rohitx
4 Replies

4. Shell Programming and Scripting

Random numbers from 0 to 1000

Hello All, I want to make a simple script which generate random number from 0 to 1000. and simply display it. Plz HELP!!!!!! Regards, Waqas Ahmed (2 Replies)
Discussion started by: wakhan
2 Replies

5. Shell Programming and Scripting

Random Numbers - Perl

Hi Guys I have a script to find Ranomd numbers. But I want to make the file to produce more random. Could u guys help me plz. In this Script I have the code that generates random in for loop and the range I have specified in my %chromlength input and out put will be like this chrno start end... (3 Replies)
Discussion started by: repinementer
3 Replies

6. Shell Programming and Scripting

Generating random numbers

Hi, I am having trouble with generating random numbers. can this be done with awk? So I have a file that looks like this: 23 30 24 40 26 34 So column1 is start and column2 is end. I want to generate 3 random #'s between start and stop: So the output will look like this: ... (9 Replies)
Discussion started by: phil_heath
9 Replies

7. UNIX for Dummies Questions & Answers

Syntax Help | unix | grep | regular expression | repetition

Hello, This is my first post so, Hello World! Anyways, I'm learning how to use unix and its quickly become apparent that a strong foundation in regular expressions will make things easier. I'm not sure if my syntax is messing things up or my logic is messing things up. ps -e | grep... (4 Replies)
Discussion started by: MykC
4 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. Homework & Coursework Questions

Random numbers

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! Write a shell script that will take the sum of two random number? Ex: Random n1 +Random n2 = result i tries to write it but i had some dufficulties ... (3 Replies)
Discussion started by: renegade755
3 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.10 19 May 2004 rand(3C)
All times are GMT -4. The time now is 08:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy