teknomatika Posted October 10, 2012 Posted October 10, 2012 ;;;Random number generation function - based on the linear ;;; congruential method as presented in Doug Cooper's book ;;; Condensed Pascal, pp. 116-117. (defun rnd (/ modulus multiplier increment random) (if (not seed) (setq seed (getvar "DATE")) ) (setq modulus 65536 multiplier 25173 increment 13849 seed (rem (+ (* multiplier seed) increment) modulus) random (/ seed modulus) ) ) (defun c:loto(/ qn cont pt disth) (setvar "luprec" 0) (setq qn 49);;Number Range (setq cont (getint "\nQuantity of numbers.? ")) (setq pt (getpoint "\nPoint to write: ")) (setq disth 1);;Horizontal space (repeat cont (setq num (fix(* qn (rnd)))) (setq cont (+ cont 1)) (command "_.text" "_non" pt 0.20 0 (rtos num)) (setq pt (list (+ (car pt)disth)(cadr pt)(caddr pt))) ) (princ) ) For fun, this basic routine is supposed to write a certain group of random numbers within a range established or to be established. The question, for which I am still not able to solve, is to not validate the number 0 and prevent the outflow of repeated numbers together. Anyone want to help? Quote
pBe Posted October 10, 2012 Posted October 10, 2012 (edited) (defun c:loto (/ qn cont pt disth lst) (setvar "luprec" 0) (setq qn 49) ;;Number Range (setq cont (getint "\nQuantity of numbers.? ")) (setq pt (getpoint "\nPoint to write: ")) (setq disth 1 [color="blue"]lst nil[/color]) ;;Horizontal space [color="blue"] (while (< (length lst) cont)[/color] (setq num (fix (* qn (rnd)))) [color="blue"](if (and (not (member num lst)) (not (zerop num))) (setq lst (cons num lst)))) (foreach val (vl-sort lst '<)[/color] (command "_.text" "_non" pt 0.20 0[color="blue"] (itoa val)[/color]) (setq pt (list (+ (car pt) disth) (cadr pt) (caddr pt))) ) (princ) ) Edited October 10, 2012 by pBe Quote
marko_ribar Posted October 10, 2012 Posted October 10, 2012 I have to add to this this note : "Realizing the number of combinations of 49 numbers with n numbers, to get full prize with loto ticket it is greater probability that you'll be hit by thunder than you'll get winning loto combination"... I would rather save my small amount of money, than participate in popular robbery for masses... M.R. Quote
teknomatika Posted October 10, 2012 Author Posted October 10, 2012 I have to add to this this note : "Realizing the number of combinations of 49 numbers with n numbers, to get full prize with loto ticket it is greater probability that you'll be hit by thunder than you'll get winning loto combination"... I would rather save my small amount of money, than participate in popular robbery for masses... M.R. Marko is a good point of view. However, every day there are those lucky ones hit by the thunder. pBe, tanks for the help. Quote
pBe Posted October 10, 2012 Posted October 10, 2012 I'm in it for the fun of debugging OP's code Quote
teknomatika Posted October 10, 2012 Author Posted October 10, 2012 pBe, By the way, how to write the numbers ordered? Tanks! Quote
pBe Posted October 10, 2012 Posted October 10, 2012 [i][b](vl-sort lst '<)[/b][/i] See updated post. Quote
teknomatika Posted October 10, 2012 Author Posted October 10, 2012 [i][b](vl-sort lst '<)[/b][/i] See updated post. pBe, tanks! Quote
Lee Mac Posted October 10, 2012 Posted October 10, 2012 Another, for fun: ([color=BLUE]defun[/color] c:lotto ( [color=BLUE]/[/color] hgt ins lst num qty ) ([color=BLUE]setq[/color] qty 6 ins ([color=BLUE]getvar[/color] 'viewctr) hgt ([color=BLUE]getvar[/color] 'textsize) ) ([color=BLUE]while[/color] ([color=BLUE]<[/color] ([color=BLUE]length[/color] lst) qty) ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]member[/color] ([color=BLUE]setq[/color] num (LM:randrange 1 49)) lst)) ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] num lst)) ) ) ([color=BLUE]foreach[/color] num ([color=BLUE]vl-sort[/color] lst '[color=BLUE]<[/color]) ([color=BLUE]entmake[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"TEXT"[/color]) '(72 . 1) '(73 . 2) '(62 . 2) ([color=BLUE]cons[/color] 10 ins) ([color=BLUE]cons[/color] 11 ins) ([color=BLUE]cons[/color] 40 hgt) ([color=BLUE]cons[/color] 07 ([color=BLUE]getvar[/color] 'textstyle)) ([color=BLUE]cons[/color] 01 ([color=BLUE]itoa[/color] num)) ) ) ([color=BLUE]entmake[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"CIRCLE"[/color]) ([color=BLUE]cons[/color] 10 ins) ([color=BLUE]cons[/color] 40 ([color=BLUE]*[/color] 1.2 hgt)) '(62 . 3))) ([color=BLUE]setq[/color] ins ([color=BLUE]cons[/color] ([color=BLUE]+[/color] ([color=BLUE]car[/color] ins) ([color=BLUE]*[/color] 3 hgt)) ([color=BLUE]cdr[/color] ins))) ) ([color=BLUE]command[/color] [color=MAROON]"_.zoom"[/color] [color=MAROON]"_C"[/color] [color=MAROON]"_non"[/color] ([color=BLUE]cons[/color] ([color=BLUE]-[/color] ([color=BLUE]car[/color] ins) ([color=BLUE]*[/color] 1.5 ([color=BLUE]1+[/color] qty) hgt)) ([color=BLUE]cdr[/color] ins)) ([color=BLUE]*[/color] ([color=BLUE]1+[/color] qty) hgt) ) ([color=BLUE]princ[/color]) ) [color=GREEN];; Rand - Lee Mac[/color] [color=GREEN];; PRNG implementing a linear congruential generator with[/color] [color=GREEN];; parameters derived from the book 'Numerical Recipes'[/color] ([color=BLUE]defun[/color] LM:rand ( [color=BLUE]/[/color] a c m ) ([color=BLUE]setq[/color] m 4294967296.0 a 1664525.0 c 1013904223.0 $xn ([color=BLUE]rem[/color] ([color=BLUE]+[/color] c ([color=BLUE]*[/color] a ([color=BLUE]cond[/color] ($xn) (([color=BLUE]getvar[/color] 'date))))) m) ) ([color=BLUE]/[/color] $xn m) ) [color=GREEN];; Random in Range - Lee Mac[/color] [color=GREEN];; Returns a pseudo-random number in a given range (inclusive)[/color] ([color=BLUE]defun[/color] LM:randrange ( a b ) ([color=BLUE]fix[/color] ([color=BLUE]+[/color] a ([color=BLUE]*[/color] (LM:rand) ([color=BLUE]-[/color] b a -1)))) ) ([color=BLUE]princ[/color]) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.