LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925

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 (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,726

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
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 (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,726

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
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 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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 (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,726

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
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 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
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: 703

Rep: Reputation: 111Reputation: 111
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
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,726

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
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: 10,668
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
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,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
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,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
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



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 04:39 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