Making Linear Function Generator more useful

I found a script that generates random linear functions based on selecting random numbers for m (slope) and b(intercept). However, it only uses positive “b” values because in the note it has the following script: content:“The function graphed to the left is `f(x)={slope}x+{yInt}`”
So it is putting in the + sign between the mx and the b. If I use a negative number, it generates the following as an example: y = 2x + - 3.

I need a way to have it show y=mx+b when a random + b value is generated and to show
y=mx-b when a -b value is generated.

Here’s an example where the content displays different forms depending on the value of the y-intercept. If it’s zero, the y-intercept isn’t shown. If it’s negative, I just removed the plus sign. If it’s positive, it is displayed in the original format in your question.

That’s exactly what I needed, thanks. I looked through the online CL documentation but couldn’t find a ROUND function. Is there one or what do you suggest as a work-around? I would like the ability to generate a random number along with" float "rather than “int” and round it to the nearest tenth.

You will want to use the graphing calculator to handle the rounding. Set the random floating number to be a variable. The round function only rounds to the nearest whole number, so here’s a workaround to round to the nearest tenth. I used the random function in the graphing calculator (I’m not sure if random is available in Activity Builder yet), but it works the same way float works in Computation Layer.

Thanks, I didn’t think it was available in the computation layer. I see that you multiply by 10 since it rounds to the nearest whole number and then divide by 10 to get it back to a decimal value.

Fun fact: You can round to any decimal place in the graphing calculator and you can put it into CL!

@cwinske has the right idea though. When a graph is available its always more reliable to use that rather than type out long strings in CL.

The first screen you sent does the rounding I want, but the second screen doesn’t seem to work. It says NaN rather than the number.

Sorry, try entering numbers into the input.

I learned two new things from this. Thanks for sharing!