only call srand once unless you want the same stream multiple times (there are use cases for that). Calling it in the loop is pointless.
the function has while(1) and no way out. If you want it to stop, give it a way to do so, for example:
srand(time(0);
for(int i = 0; i < 10; i++)
cout << rand() << endl;
or whatever you want to do.
c++ does not have a keypressed type function but libraries do, so if you want a while not keypressed or while keypressed not equal '2' then you need a library to do it, or a fair bit of work and know how to do it yourself (embed assembly, or tap into the device buffer). You can also do it with threads.
C++ has bool type built-in. You don't need to use an enum.
But anyway... your randomNumber function consistes of an infinite where you keep re-seeding the RNG and then calling and printing the random number.
Your main function already has a loop in it, and entering 2 should cause you to break out of it. What do you want randomNumber to do? Generate a single random number? If so, remove the while(1) loop.
Also, you only should seed rand once. Put line 51 (the srand call) at the beginning of main.