LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2017, 02:57 PM   #46
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915

Quote:
Originally Posted by BW-userx View Post
OIC
don't forget to close your eyes just before you run it.
You should ask for a share if he wins it using your method.
 
Old 04-26-2017, 04:27 PM   #47
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by hydrurga View Post
You should ask for a share if he wins it using your method.
Good point
 
Old 04-27-2017, 07:27 AM   #48
linustalman
Senior Member
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 10 (Buster) x64
Posts: 4,504

Original Poster
Rep: Reputation: 445Reputation: 445Reputation: 445Reputation: 445Reputation: 445
Quote:
Originally Posted by hydrurga View Post
You should ask for a share if he wins it using your method.
 
Old 04-27-2017, 08:14 AM   #49
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by linustalman View Post
LAWS of Probability?

if you use on set of numbers and the odds are say: 3000 to 1
you play that set of numbers, it does NOT hit. So you pick a different set of numbers, the odds still stay the same. 3000 to 1
but what if you keep that same set of numbers and play them again. Will that change the odds to 2999 to 1 because one of them was already used?

in other words if one keep playing the odds using the same set of numbers, are the odds of wining increased due to it has to hit eventually because of the process of elimination?
 
Old 04-27-2017, 08:18 AM   #50
linustalman
Senior Member
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 10 (Buster) x64
Posts: 4,504

Original Poster
Rep: Reputation: 445Reputation: 445Reputation: 445Reputation: 445Reputation: 445
Post

Quote:
Originally Posted by BW-userx View Post
LAWS of Probability?

if you use on set of numbers and the odds are say: 3000 to 1
you play that set of numbers, it does NOT hit. So you pick a different set of numbers, the odds still stay the same. 3000 to 1
but what if you keep that same set of numbers and play them again. Will that change the odds to 2999 to 1 because one of them was already used?

in other words if one keep playing the odds using the same set of numbers, are the odds of wining increased due to it has to hit eventually because of the process of elimination?
I would say that if fresh random numbers were used to play the lotto every week vs using the same randomly picked numbers every week -- the odds of winning the jackpot would be the same.
 
Old 04-27-2017, 08:21 AM   #51
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915
Quote:
Originally Posted by BW-userx View Post
LAWS of Probability?

if you use on set of numbers and the odds are say: 3000 to 1
you play that set of numbers, it does NOT hit. So you pick a different set of numbers, the odds still stay the same. 3000 to 1
but what if you keep that same set of numbers and play them again. Will that change the odds to 2999 to 1 because one of them was already used?

in other words if one keep playing the odds using the same set of numbers, are the odds of wining increased due to it has to hit eventually because of the process of elimination?
No, the odds of winning are exactly the same. The probability of certain numbers being chosen in any draw is independent of any previous results.
 
Old 04-27-2017, 08:29 AM   #52
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by hydrurga View Post
No, the odds of winning are exactly the same. The probability of certain numbers being chosen in any draw is independent of any previous results.
that sound so "text book" convincing.

though that was the other side of my thought, I just didn't add it in here. Because the rationalization of "if you play that same number long enough it will hit eventually". can be a true statement.

I do suppose the rationalization falls into that is the same as the pool table theory.
If you hit the ball hard enough, it will eventually fall into the hole (pocket).

Last edited by BW-userx; 04-27-2017 at 08:37 AM.
 
Old 04-28-2017, 07:42 AM   #53
linustalman
Senior Member
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 10 (Buster) x64
Posts: 4,504

Original Poster
Rep: Reputation: 445Reputation: 445Reputation: 445Reputation: 445Reputation: 445
Question

Quote:
Originally Posted by BW-userx View Post
...

shuf
Code:
userx%slackwhere ⚡ ~ ⚡> shuf -i1-47 -n6
16
23
33
19
22
31
...
Would it be possible to output the numbers on the same line and separated by commas?
 
Old 04-28-2017, 07:59 AM   #54
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915Reputation: 2915
Quote:
Originally Posted by linustalman View Post
Would it be possible to output the numbers on the same line and separated by commas?
One alternative:

Code:
shuf -i1-47 -n6 | sed ':a;N;$!ba;s/\n/,/g'
Sorted:

Code:
shuf -i1-47 -n6 | sort -n | sed ':a;N;$!ba;s/\n/,/g'

Last edited by hydrurga; 04-28-2017 at 08:02 AM. Reason: sorted
 
1 members found this post helpful.
Old 04-28-2017, 08:04 AM   #55
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,513
Blog Entries: 3

Rep: Reputation: 2784Reputation: 2784Reputation: 2784Reputation: 2784Reputation: 2784Reputation: 2784Reputation: 2784Reputation: 2784Reputation: 2784Reputation: 2784Reputation: 2784
Or a perl variant:

Code:
shuf -i 1-47 -n 6 | perl -p -00 -e 's/\n(?!\Z)/,/g'
 
1 members found this post helpful.
Old 04-28-2017, 08:09 AM   #56
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 698

Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by BW-userx View Post
that sound so "text book" convincing.

though that was the other side of my thought, I just didn't add it in here. Because the rationalization of "if you play that same number long enough it will hit eventually". can be a true statement.

I do suppose the rationalization falls into that is the same as the pool table theory.
If you hit the ball hard enough, it will eventually fall into the hole (pocket).
I think it all depends on the method how the random numbers are generated.

Given a bowl with 47 balls numbered 1 - 47, there's no chance you'll have a duplicate, unless balls are thrown back in the bowl.
The shuf command resembles this method, and that makes it a nice and quick method.

On the other hand; if each time a number is generated is equal and completely random, there's an increasing chance that there will be duplicates.

The issue with this kind of thing is indeed the duplicates; are they possible, how do they affect the outcome... I've never been one for lotteries, so actually I have no idea what the real question is... I find this initial question intriguing in that aspect, one I often detect at work as well; people think they have one question... until they speak with us... they return with more questions. All because the question has to be exact, because the answer needs to be exact.
 
Old 04-28-2017, 08:12 AM   #57
linustalman
Senior Member
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 10 (Buster) x64
Posts: 4,504

Original Poster
Rep: Reputation: 445Reputation: 445Reputation: 445Reputation: 445Reputation: 445
Quote:
Originally Posted by Turbocapitalist View Post
Or a perl variant:

Code:
shuf -i 1-47 -n 6 | perl -p -00 -e 's/\n(?!\Z)/,/g'
And also have them sorted in ascending order?
 
Old 04-28-2017, 08:14 AM   #58
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187
The odds of a six-digit draw from 47 is (1/47) + (1/46) + (1/45) + (1/44) + (1/43) + (1/42). As each digit is drawn, the size of the remaining pool of numbers decreases by one.
 
Old 04-28-2017, 08:40 AM   #59
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,814

Rep: Reputation: 639Reputation: 639Reputation: 639Reputation: 639Reputation: 639Reputation: 639
Quote:
Originally Posted by linustalman View Post
Would it be possible to output the numbers on the same line and separated by commas?
This code ...
Code:
SixRandom=$(shuf -i1-47 -n6|paste -sd,)
echo "SixRandom =" $SixRandom
... produced this result ...
Code:
SixRandom = 46,29,36,17,10,16
Daniel B. Martin
 
2 members found this post helpful.
Old 04-28-2017, 08:47 AM   #60
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,814

Rep: Reputation: 639Reputation: 639Reputation: 639Reputation: 639Reputation: 639Reputation: 639
Quote:
Originally Posted by linustalman View Post
And also have them sorted in ascending order?
This code ...
Code:
SixRandom=$(shuf -i1-47 -n6|sort -n|paste -sd,)
echo "SixRandom =" $SixRandom
... produced this result ...
Code:
SixRandom = 5,18,32,36,41,44
Daniel B. Martin
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed - replacing random numbers followed with space and more random chars gluposti Linux - Newbie 7 05-07-2012 07:36 PM
Generate random numbers in C program ssaslam Linux - Newbie 5 10-23-2008 08:28 PM
Generate random numbers in C program ssaslam Linux - Newbie 1 02-21-2008 11:39 PM
using /dev/random to output random numbers on a text file guguma Programming 4 04-02-2007 01:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration