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

  • SEARCH
  • Home
  • 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 515445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:37:44+00:00 2026-05-13T07:37:44+00:00

This is to do with the following code, which uses a for loop to

  • 0

This is to do with the following code, which uses a for loop to generate a series of random offsets for use elsewhere in the program.

The index of this for loop is unused, and this is resulting in the ‘offending’ code being highlighted as a warning by Eclipse / PyDev

def RandomSample(count):    
    pattern = []
    for i in range(count):
        pattern.append( (random() - 0.5, random() - 0.5) )

    return pattern

So I either need a better way to write this loop that doesn’t need a loop index, or a way to tell PyDev to ignore this particular instance of an unused variable.

Does anyone have any suggestions?

  • 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-05-13T07:37:45+00:00Added an answer on May 13, 2026 at 7:37 am
    randomSample = [(random() - 0.5, random() - 0.5) for _ in range(count)]
    

    Sample output, for count=10 and assuming that you mean the Standard Library random() function:

    [(-0.07, -0.40), (0.39, 0.18), (0.13, 0.29), (-0.11, -0.15),\
    (-0.49, 0.42), (-0.20, 0.21), (-0.44, 0.36), (0.22, -0.08),\
    (0.21, 0.31), (0.33, 0.02)]
    

    If you really need to make it a function, then you can abbreviate by using a lambda:

    f = lambda count: [(random() - 0.5, random() - 0.5) for _ in range(count)]
    

    This way you can call it like:

    >>> f(1)
    f(1)
    [(0.03, -0.09)]
    >>> f(2)
    f(2)
    [(-0.13, 0.38), (0.10, -0.04)]
    >>> f(5)
    f(5)
    [(-0.38, -0.14), (0.31, -0.16), (-0.34, -0.46), (-0.45, 0.28), (-0.01, -0.18)]
    >>> f(10)
    f(10)
    [(0.01, -0.24), (0.39, -0.11), (-0.06, 0.09), (0.42, -0.26), (0.24, -0.44) , (-0.29, -0.30), (-0.27, 0.45), (0.10, -0.41), (0.36, -0.07), (0.00, -0.42)]
    >>> 
    

    you get the idea…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 312k
  • Answers 312k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you are using a GNU compiler, the compiler can… May 13, 2026 at 10:33 pm
  • Editorial Team
    Editorial Team added an answer I like to beat dead horses! :) The "lightest" way… May 13, 2026 at 10:33 pm
  • Editorial Team
    Editorial Team added an answer I believe the simplest solution to getting the behavior desired… May 13, 2026 at 10:33 pm

Related Questions

I'm very infrequently seeing the following error logged on a website I manage: Arguments
I'm writing an iPhone app that is mainly centered around grid patterns, so I
I have the following code which re-uses a CookieContainer which logs in on the
This is a generic C++ design question. I'm writing an application that uses a
I am trying to get a header that will work with Apache, IIS 6,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.