random function script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting random function script
# 1  
Old 09-14-2006
Error random function script

hi,

I need a command which picks the records randomly from the file.
For example. i am having some 10000 entries in a file and need to extract the lines randomly without repeating the numbers.

Do anybody have any idea on how to get this out.
# 2  
Old 09-14-2006
check if this helps:

#!/bin/bash

RANGE=1000
number=$RANDOM
let "number %= $RANGE"
echo "Random number less than $RANGE --- $number"
# 3  
Old 09-14-2006
Alternative , in Python:

Code:
>>> import random
>>> length = 10000
>>> all = open("file_with_records.txt").readlines()
>>> for num in range(0,length-1):
... 	randnum = random.randint(0,length-1) #generate random num
... 	print all[randnum]

# 4  
Old 09-14-2006
and in Perl:

#!/usr/bin/perl

use strict;
my $limit = 10000;

my $random_number = int (rand $limit);
print "random number: $random_number \n";
# 5  
Old 09-15-2006
Thanks a lot,

This is working now Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

2. Shell Programming and Scripting

Script that will random choose an IP address

Hi, I need to write a bash script that will random choose and login into these below ip addresses. 192.168.116.130 192.168.116.131 192.168.116.132 192.168.116.133 I'm new into scripting and I need to enhance my logic. Below is what i did ... (4 Replies)
Discussion started by: Milon
4 Replies

3. Shell Programming and Scripting

Random script error with rndc

Hello coders, been running into an strange behavior into one of my script and i'm wondering if my code wouldn't be responsible. Bash on rhel 5.7 This is a basic check to see if bind is up and running on server. # rndc check INFO="Checking rndc" for DNS_SERVER in ${DNS_MASTER_SERVERS};... (10 Replies)
Discussion started by: maverick72
10 Replies

4. Shell Programming and Scripting

Random number generating script?

Having a hard time with this. Very new to scripting and linux. Spent all sunday trying to do this. Appreciate some help and maybe help breaking down what the syntax does. Create a Bash program. It should have the following properties • Creates a secret number between 1 and 100 i. The... (3 Replies)
Discussion started by: LINUXnoob15
3 Replies

5. 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

6. Shell Programming and Scripting

Function - play # uses mplayer random directories

I have this in my .bashrc and use it to play my music. It is organized by directories and this will play them in random order: play(){ ## play directories with mplayer (random) if then # if no option show music types echo -n " play {directory|style} Styles: -------" find... (0 Replies)
Discussion started by: bdragon
0 Replies

7. 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

8. Ubuntu

expect script for random password and random commands

Hi I am new to expect. Please if any one can help on my issue its really appreciable. here is my issue: I want expect script for random passwords and random commands generation. please can anyone help me? Many Thanks in advance (0 Replies)
Discussion started by: vanid
0 Replies

9. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

10. Shell Programming and Scripting

random script termination

I'm writing a script to archive data. First, the files are all rsync'd to the archive directory via NFS mounts(I know not the most efficient, but the only choice in this situation), then I use md5sum to validate the transfers. During execution of the script, it will exit for no apparent reason. It... (6 Replies)
Discussion started by: mph
6 Replies
Login or Register to Ask a Question