2313
|
1 ## Copyright (C) 1996 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
245
|
19 |
2311
|
20 ## usage: texas_lotto |
|
21 ## |
|
22 ## Pick 6 unique numbers between 1 and 50 that are guaranteed to win |
|
23 ## the Texas Lotto. |
|
24 ## |
|
25 ## See also: rand |
4
|
26 |
2311
|
27 function picks = texas_lotto () |
4
|
28 |
|
29 if (nargin != 0) |
904
|
30 warning ("win_texas_lotto: ignoring extra arguments"); |
4
|
31 endif |
|
32 |
|
33 picks = zeros (1,6); |
|
34 picks (1) = round (50-49*(1-rand)); |
|
35 n = 2; |
|
36 while (n < 7) |
|
37 tmp = round (50-49*(1-rand)); |
|
38 equal = 0; |
|
39 for i = 1:n |
|
40 if (tmp == picks (i)) |
|
41 equal = 1; |
|
42 break; |
|
43 endif |
|
44 endfor |
|
45 if (! equal) |
|
46 picks (n) = tmp; |
|
47 n++; |
|
48 endif |
|
49 endwhile |
|
50 |
|
51 picks = sort (picks); |
|
52 |
|
53 endfunction |