Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:12:05+00:00 2026-06-14T20:12:05+00:00

My program is very complex, I am providing a simpler version below: while True:#This

  • 0

My program is very complex, I am providing a simpler version below:

while True:#This first part asks the user if he wants to run in deterministic mode(explained later) If he does then deterministic is given a value of 1, else, it is given a value of two.
    mode= input("Would you like to start the program in deterministic mode?(y/n)")
    for i in mode:
        if i not in ('yYnN'):
            print('Please enter either a \'y\' or an \'n\', Please try again')
            break
    else:
        break

if mode=='y' or mode== 'Y':
    deterministic= 1
elif mode=='n' or mode=='N':
    deterministic= 2

Now Below is some code that uses the above code. It is an if-elif statement where if deterministic is ==1 then a function will run, and if deterministic==2 then a different function will run.

        if deterministic==2:#position,time, and energy variables will come from the function updateDisplayAllVar(....)

            position,time,energy=updateDisplayAllVar(selection,position,time,energy)
        elif deterministic==1:#position,time, and energy variables will come from the function deterministic(....)

            position,time,energy=deterministic(selection,position,time,energy)

Now I will show you the two functions from the above code. The problem lies in them I believe. The first function gives a random number, and a possibly different random number every time. The second function uses the .seed to limit the random number to the SAME “random” number each time.

def updateDisplayAllVar(selection,position,time,energy):

if selection=='w' or selection =='W':
    energy= energy
    position= position+1
    time=time+1
elif selection=='j' or selection =='J':
    energy= energy-1
    position= position+2
    time=time+1 
elif selection=='r' or selection =='R':
    energy= energy-random.randrange(1,2+1)
    position= position+random.randrange(1,4+1)
    time=time+1
elif selection=='f' or selection =='F':
    energy= energy- random.randrange(3,5+1)
    position= position+random.randrange(3,8+1)
    time=time+1



def deterministicMode(selection,position,time,energy):

    if selection=='w' or selection =='W':
        energy= energy
        position= position+1
        time=time+1
    elif selection=='j' or selection =='J':
        energy= energy-1
        position= position+2
        time=time+1 
    elif selection=='r' or selection =='R':
        random.seed(1)
        energy= energy-random.randrange(1,2+1)
        position= position+random.randrange(1,4+1)
        time=time+1
    elif selection=='f' or selection =='F':
        random.seed(3)
        energy= energy- random.randrange(3,5+1)
        position= position+random.randrange(3,8+1)
        time=time+1

Now my problem is… that, with this code, even if I do not choose to be in deterministic(no random number) mode, I still get numbers that are not random and are based on the second function. That is, even though there are two functions up there and I’m asking each function to run based on the users input… It is always deterministicMode(selection,position,time,energy) that runs. Does anyone know a fix. Please let me know if anything is unclear and I will fix it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:12:05+00:00Added an answer on June 14, 2026 at 8:12 pm

    Just re-seed your RNG with the current system time to make it “random” again:

    def deterministicMode(selection,position,time,energy):
        random.seed()  # <-- Add this line right here
    
        if selection=='w' or selection =='W':
            energy= energy
            position= position+1
            time=time+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I made this (very simple) program with a swing GUI with NetBeans, and
Take a guess ... how long will this program take to produce the very
I have a complex type in my program that results in very long line
I have a problem with debugging sessions. My program executes very well in a
I am running a very simple program, which is trying to list files in
I start with a very simple program: #include <TBString.h> int main(int argv, char** argc)
Here is a very simple program: a = [[]]*3 print str(a) a[0].append(1) a[1].append(2) a[2].append(3)
It's a very simple program. I have a function defined on the top and
I have a very large program which I have been compiling under visual studio
Here's a very simple program using the function: #include <windows.h> #include <tchar.h> #include <atlstr.h>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.