"Undefined behavior" means that anything can happen. This also includes that different things might happen on each run of the program.
For example, if you use uninitialized memory it might be different from program run to program run what exactly that memory contains.
A simple example:
int main() {
char s[1024];
s[1023] = '\0';
std::cout << s << std::endl;
}
This will usually print a different string each time it is run. It doesn't use any heap allocations and I don't think it's even any undefined behavior, so probably it's not the intended solution to your question.
Another example would be that new
can return different addresses on each program run (also no UB here):
int main(void) {
std::cout << new int << std::endl;
}
So even without undefined behavior there are sources of "randomness", so certainly also with undefined behavior different things can happen each program run.