Combination of 6 nos


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combination of 6 nos
# 1  
Old 02-24-2016
Combination of 6 nos

Hi folks,

I have a numbers from 1-100 and from these nos I have 30 numbers.. From this 30 nos, I have to generate a combination of 6 nos... this 30 numbers will range from 1-100... ( FYI: This is not a lottery game - just kidding) ... I am trying out this in a shell script.. any ideas ?
# 2  
Old 02-24-2016
Any attempts/ideas/thoughts from your side?

How about using a random number as the index into the array[100]?
# 3  
Old 02-24-2016
As an addendum to RudiC's reply remember to allow for any duplicate numbers in generating the array _randomly_.

Once you have the array then randomly select your 6 numbers from the array of 30 numbers, again checking for possible duplicates...
# 4  
Old 02-25-2016
There is a way to create an array of a range of random numbers with each one occurring once with no duplicates.
  1. Populate the first array with all possible values, call it "deck".
  2. Varying a (loop ) subscript from last occurrence to first, get a random number, multiply it by that subscript, and floor it to get a new subscript.
  3. Use the new subscript to move an item from "deck" to the loop subscript occurrence of the array "shuffle".
  4. Move the last active occurrence of "deck" (looping subscript) to the new subscript occurrence of deck.
When the last occurrence of deck is chosen, the last item in "deck" will be moved to its own position but, because the looping subscript is decreasing, it will never be referred to again. The array "shuffle" is now ready to use.
If the same occurrence of "deck" is chosen again, it will contain a new value.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Kill -9 -1 combination

Good morning, In a Production environment ive seen this command that kills processes kill -9 -1 Because i am in a production environmet i can not execute this comamnd, so i would like to know what is the difference for the conventional kill -9 PID ? Thanks a lot (11 Replies)
Discussion started by: alexcol
11 Replies

2. Programming

6 digits combination

Is there any program that can create 6 digit numbers with: (DIGIT_1)+(DIGIT_2)+(DIGIT_3)+(DIGIT_4)+(DIGIT_5)+(DIGIT_6)=10 Any perl or C also can. Anyone can help me? Thank you (6 Replies)
Discussion started by: Tzeronone
6 Replies

3. Shell Programming and Scripting

New sequence nos to be added in new files

Hi All, Please help me in below request. Got multiple files in a dir ex: /os . from each file need to filter based upon first field (field only has 1,2,3 or 4) and then put it in different files based on the Field 1. But need to generate a sequence while inserting and the sequence number needs... (1 Reply)
Discussion started by: rdakshn
1 Replies

4. Shell Programming and Scripting

Combination of numbers

Hello Group, I have a file of data that contain 1 2 3 4 5 I request you help with a shell script for generate all posible combination of these numbers with the following output: Example: 1 + 2 + 3 + 4 + 5 = 2 + 2 + 3 + 4 + 5 = 3 + 2 + 3 + 4 + 5 = Thanks in advance. Carlos (7 Replies)
Discussion started by: csierra
7 Replies

5. Shell Programming and Scripting

Escape and combination

Hi I have 2 files like: file1 a 12 b 1 a 3 file2 a 9 c 0 a 8 and i would like to get a 12 a 9 a 3 a 8 i can do it with grep and paste with 3 lines. I tried to combine using: (3 Replies)
Discussion started by: Dedalus
3 Replies

6. UNIX for Dummies Questions & Answers

Delete repeated nos in a file

Hi, I need to delete repeated nos in a file and finally list the count. Can some one assist me? file: 12345 12345 56345 12345 23896 Output needed: 12345 56345 23896 Total count:3 Thanks (2 Replies)
Discussion started by: gini
2 Replies

7. UNIX for Dummies Questions & Answers

combination of two commands

I want to show a output like this Lee Ballancore PID TTY TIME CMD 31799 pts/3 00:00:00 vim 31866 pts/3 00:00:00 vim 2495 pts/7 00:00:00 vim 8368 pts/0 00:00:00 vim 9544 pts/2 00:00:00 ps Alistairr Rutherford PID TTY TIME CMD 8368 pts/0 00:00:00 vim 9544 pts/2 00:00:00 ps ... (3 Replies)
Discussion started by: nehaquick
3 Replies

8. UNIX for Dummies Questions & Answers

Combination Of commands

Hello All, I just wanted to know what are the different ways of using commands in combination. The most common one which i know is using pipes. Also grouping is also done like ( ls; date) where output of both the commands is displayed. Are there any other ways of combining various... (2 Replies)
Discussion started by: rahulrathod
2 Replies

9. Filesystems, Disks and Memory

Partition combination

Hi all I've got MacOSX server which is a UNIX based system. I've got 2 partiontion an I like to make just one partition on he disk without loosing any data on part1. Is there a way to do that kind of thing in UNIX or do I have to format everything and put up the system again? Thanx for reading... (3 Replies)
Discussion started by: gardarm
3 Replies
Login or Register to Ask a Question