benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 4b2c1927-01f1-5581-9c02-1a77ec452654

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import random
import string

def task_func(max_length, n_samples, seed=None):
    """Generate a list containing random strings of lowercase letters. Each string's length varies from 1 to `max_length`.
    An optional seed can be set for the random number generator for reproducible results.

    Note:
    The function utilizes the `random.choices` function to generate random strings and combines them into a list.

    Parameters:
    max_length (int): The maximum length of the strings.
    n_samples (int): The number of strings to return.
    seed (int, optional): A seed for the random number generator. If None, the generator is initialized without a seed.

    Returns:
    list: A list containing random strings. Each string is a random combination of lowercase letters, 
    and their lengths will vary from 1 to `max_length`.

    Requirements:
    - random
    - string

    Raises:
    ValueError: If max_length is smaller than 1.

    Example:
    >>> task_func(3, 12, seed=12)
    ['gn', 'da', 'mq', 'rp', 'aqz', 'ex', 'o', 'b', 'vru', 'a', 'v', 'ncz']
    >>> task_func(5, n_samples=8, seed=1)
    ['ou', 'g', 'tmjf', 'avlt', 's', 'sfy', 'aao', 'rzsn']

    """

instruct prompt

Generate a list containing random strings of lowercase letters. Each string's length varies from 1 to `max_length`. An optional seed can be set for the random number generator for reproducible results.
Note that: The function utilizes the `random.choices` function to generate random strings and combines them into a list.
The function should raise the exception for: ValueError: If max_length is smaller than 1.
The function should output with:
    list: A list containing random strings. Each string is a random combination of lowercase letters,
    and their lengths will vary from 1 to `max_length`.
You should write self-contained code starting with:

Code

import random
import string
def task_func(max_length, n_samples, seed=None):

code prompt

Code

import random
import string
def task_func(max_length, n_samples, seed=None):

entry point

task_func

libs

  • random
  • string

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import