I need a function for a program I'm writing

I need a function for a program I'm writing

Postby Guest » Fri Jun 05, 2020 8:22 pm

Hello friends,

I'm writing a program that randomly generates markup in sample text. The purpose is to create test cases for another program I'm writing. The program works fine for the most part but it tends to group closing tags at the back of the segment of text. This indicates to me that when the text reaches its end, there are still several tags open which I then close in the program. I'm trying to reduce this so that the end result is more natural and the way it works is I have a function that generates a "true" or "false" depending on a random number between [0.0, 1.0). The function works by comparing that random number to a "factor" and the math problem is in generating this factor. I have certain rules that I want this factor to follow but I'm having trouble figuring out the math because it involves concepts I haven't used since High School and even then, I don't know that I'd be able to have done it when it was fresh. The program works by generating a list of words and then randomly, between those words, it inserts an opening or closing tag. So there's a length to that list (that doesn't change because the tags are inserted into a copy of that list) and a length of how far in that list the program has progressed. There is also a stack that indicates how nested the tags are (i.e. how many tags are open and need to be closed)

Here are the rules:
The deeper the nesting, the more and more likely it is that the tag will close.
The closer to the end of the list, the more likely it is that the tag will close.
The resulting number that is then compared to the random number must be in the range [0.0, 1.0).
The relationship between the depth and the proximity to the end of the list to the resulting number should be sort of exponential. The middle 50% is where the more drastic change should be and then it should approach the limits on either side. i.e. the graph for either should be like an easing curve in animation where it's shallow then it curves upward very steeply and then goes back to shallow again approaching 1.0. It should look like the cubic variant of this if graphed:

Image

I'm thinking that I'll need to calculate both and then compare them to see which is greater and compare that to the random number.
Guest
 

Re: I need a function for a program I'm writing

Postby Guest » Tue Jun 23, 2020 9:48 am

That looks like a "logistic" curve. It is described at
https://en.wikipedia.org/wiki/Logistic_function

I can't give a more precise answer since you don't give specific numeric values.
Guest
 

Re: I need a function for a program I'm writing

Postby CharlesAlgran » Fri Sep 03, 2021 12:27 pm

Guest wrote:That looks like a "logistic" curve. It is described at
https://en.wikipedia.org/wiki/Logistic_function

I can't give a more precise answer since you don't give specific numeric values.

:idea: thank u

CharlesAlgran
 
Posts: 3
Joined: Fri Sep 03, 2021 12:23 pm
Reputation: 0


Return to Functions, Graphs, Derivatives



Who is online

Users browsing this forum: No registered users and 2 guests