2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
2313
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
245
|
18 |
3449
|
19 ## -*- texinfo -*- |
3500
|
20 ## @deftypefn {Function File} {} texas_lotto () |
2311
|
21 ## Pick 6 unique numbers between 1 and 50 that are guaranteed to win |
|
22 ## the Texas Lotto. |
5642
|
23 ## @seealso{rand} |
3426
|
24 ## @end deftypefn |
4
|
25 |
2314
|
26 ## Author: jwe |
|
27 |
2311
|
28 function picks = texas_lotto () |
4
|
29 |
|
30 if (nargin != 0) |
5835
|
31 warning ("texas_lotto: ignoring extra arguments"); |
4
|
32 endif |
|
33 |
|
34 picks = zeros (1,6); |
|
35 picks (1) = round (50-49*(1-rand)); |
|
36 n = 2; |
|
37 while (n < 7) |
|
38 tmp = round (50-49*(1-rand)); |
|
39 equal = 0; |
|
40 for i = 1:n |
|
41 if (tmp == picks (i)) |
|
42 equal = 1; |
|
43 break; |
|
44 endif |
|
45 endfor |
|
46 if (! equal) |
|
47 picks (n) = tmp; |
|
48 n++; |
|
49 endif |
|
50 endwhile |
|
51 |
|
52 picks = sort (picks); |
|
53 |
|
54 endfunction |