5 ms·
> Write a program for a weighted random choice generator. Use that program to say ‘left’ about 80% of the time and 'right' about 20% of the time. Simply reply
by bagrow 2y ago
> Write a program for a weighted random choice generator. Use that program to say ‘left’ about 80% of the time and 'right' about 20% of the time. Simply reply with left or right based on the output of your program. Do not say anything else.
Running once, GPT-4 produced 'left' using:
import random
def weighted_random_choice():
choices = ["left", "right"]
weights = [80, 20]
return random.choices(choices, weights)[0]
# Generate the choice and return it
weighted_random_choice()
- HPsquared 2y agoDid it run the program? Seems it just needs to take that final step.
- pulvinar 2y agoI ran it a few times (in separate sessions, of course), and got 'right' some times, as expected.
- littlestymaar 2y agoOnce again, the actual intelligence is behind the keyboard, nudging the LLM to do the correct thing.
- ziml77 2y agoMy prompt didn't even ask for code: > You are a weighted random choice generator. About 80% of the time please say ‘left’ and about 20% of the time say ‘right’. Simply reply with left or right. Do not say anything else. Give me 100 of these random choices in a row. It generated the code behind the scenes and gave me the output. It also gave a little terminal icon I could click at the end to see the code it used: import numpy as np # Setting up choices and their weights choices = ['left', 'right'] weights = [0.8, 0.2] # Generating 100 random choices based on the specified weights random_choices = np.random.choice(choices, 100, p=weights) random_choices