Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: porkchop@invalid.foo (Mike Sanders) Newsgroups: comp.lang.awk Subject: Re: 100 Random Single Variable Linear Equations Date: Sat, 7 Dec 2024 20:42:11 -0000 (UTC) Organization: A noiseless patient Spider Lines: 38 Sender: Mike Sanders Message-ID: References: Injection-Date: Sat, 07 Dec 2024 21:42:11 +0100 (CET) Injection-Info: dont-email.me; posting-host="90fb1f8e178bcc6a3c524255a69fe911"; logging-data="3491827"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lKPieOMk0/0bL7om2dSHg" User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64)) Cancel-Lock: sha1:onYdn+T5XZ3z3gVDM1N9PuvmxME= Bytes: 2285 Janis Papanagnou wrote: > The program could be extended by two principle additions/changes. > > One is to allow negative integral numbers for a, b, c; in that case > you don't even need the "random operator" logic as a side effect. > Since you are using only natural numbers in your formulas you may > want to stay within the domain of integral numbers also in the > results; that would require to check that condition before storing > an accepted formula, or to synthesize such formulas in the first > place. > > Just some more ideas. 'n' (at least for leading coefficient). but... this only tackles 'a'. 'b' & 'c' remain untouched. i must think about this more... do { a = rnd(1, 20) # random value 1 to 20 b = rnd(1, 20) # random value 1 to 20 c = rnd(1, 99) # random value 1 to 50 z = (rnd(1, 2) == 1) ? "+" : "-" # random operator n = (rnd(1, 2) == 1) ? "-" : "" # random negative coefficient e = sprintf("%s%dx %s %d = %d", n, a, z, b, c) # formatted equation # Store equation in array if it doesn't already exist if (!(e in equ)) { equ[e] = 1 # mark element as reserved u++ # increment u for each unique equation } } while (u < 100) -- :wq Mike Sanders