473,394 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Random word

keyvanrahmadi
I am trying to undcerstand how to randomise an out of the file. My file is currently consisnt of 10 words as follow:

word1, word2, word3, word4, etc....

Expand|Select|Wrap|Line Numbers
  1. cat words | cut -d" " -f1
  2.  
this will give me the first word in the first field. since there is multiple words, how do you randomise the selection of the words?

K
May 18 '07 #1
3 2686
ghostdog74
511 Expert 256MB
I am trying to undcerstand how to randomise an out of the file. My file is currently consisnt of 10 words as follow:

word1, word2, word3, word4, etc....

Expand|Select|Wrap|Line Numbers
  1. cat words | cut -d" " -f1
  2.  
this will give me the first word in the first field. since there is multiple words, how do you randomise the selection of the words?

K
just an example
Expand|Select|Wrap|Line Numbers
  1. word=$(awk 'BEGIN{FS=",";srand()}
  2. {
  3.       for (i=1;i<=NF;i++) {
  4.         word[i]=$i
  5.       }   
  6.       print word[int(rand() * NF )]
  7. }
  8. ' "file")
  9. echo $word
  10.  
May 18 '07 #2
just an example
Expand|Select|Wrap|Line Numbers
  1. word=$(awk 'BEGIN{FS=",";srand()}
  2. {
  3.       for (i=1;i<=NF;i++) {
  4.         word[i]=$i
  5.       }   
  6.       print word[int(rand() * NF )]
  7. }
  8. ' "file")
  9. echo $word
  10.  
iam not familiar with awk.. can you explain that line to me please?

K
May 18 '07 #3
arne
315 Expert 100+
I am trying to undcerstand how to randomise an out of the file. My file is currently consisnt of 10 words as follow:

word1, word2, word3, word4, etc....

Expand|Select|Wrap|Line Numbers
  1. cat words | cut -d" " -f1
  2.  
this will give me the first word in the first field. since there is multiple words, how do you randomise the selection of the words?

K
If you want to do that only with bash, you may use arrays and random values. Look for $RANDOM.

HTH,
arne
May 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Hans A | last post by:
I have a textfile "textfile.txt" containing a list of words. There is one word on each line. I want to pick two random lines from this textfile, and I have tried to do something like: //Loading...
5
by: Alistair | last post by:
Hello folks... this is my first post in here. I'm new to ASP having done all my previous work in Flash and bog standard HTML. Only been learning for a couple of weeks. anyway...I have been...
23
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you...
20
by: Levi Campbell | last post by:
Hi, I'm working on a random number generator using the internet as a way to gather entropy, I have two questions. 1. is there a way to capture the internet stream? 2. how would I skip every 2nd,...
10
by: muttaa | last post by:
Hi everybody, May i know how to write a code that generates random numbers as many times as one would want ? i.e. like the standard function 'rand()' or may i get the basic logic behind it ? ...
1
by: gry | last post by:
I want a function (or callable something) that returns a random word meeting a criterion. I can do it like: def random_richer_word(word): '''find a word having a superset of the letters of...
7
by: Jay | last post by:
How would I be able to grab random words from an internet source. I'd like to grab a random word from a comprehensive internet dictionary. What would be the best source and the best way to go...
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
38
by: Andrea | last post by:
Hi, Anyone could me suggest how to create a function that generates a random string? The function should be: int _RandomString(char** str,int len); so, it takes an empty string str and it puts...
10
by: mdmytryk | last post by:
Simple question here. Im trying to figureout how to write a program in such a way that when a word is entered, the output is each individual letter of that word in a random order. so if pizza is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.