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 8448409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:25:11+00:00 2026-06-10T10:25:11+00:00

I currently have the following function, but is there a more efficient way to

  • 0

I currently have the following function, but is there a more efficient way to generate a random integer within a range and exclude a specific integer in Matlab?

function aNew = random(a)
aMin = a-100;
aMax = a+100;
aNew = a;
while aNew == a
    aNew = randi([aMin, aMax]);
end
  • 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-10T10:25:13+00:00Added an answer on June 10, 2026 at 10:25 am

    You can use the function randsample to draw samples from a specified distribution.

    Something like this should work fine

    sampleRange = [1, 100];  % sample from 1 to 100
    noSample = 50; % lets exclude 50
    pop2Sample = [range(1):noSample-1, noSample+1:range(2)]; %create the population
    
    sample = randsample(pop2Sample,1); %draw a single sample
    

    Update

    If you wanted to exclude multiple values from your population you could use the setdiff function.

    pop2Sample = 1:100;  % sample from 1 to 100
    noSample = 0:10:100 % lets exclude any all multiples of ten
    pop2Sample = setdiff(pop2Sample, noSample);
    
    sample = randsample(pop2Sample,1); %draw a single sample
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to have the following code written more efficiently? Please note
I currently have the following setup in my module. public function onBootstrap( EventInterface $e
i have following function: function fnGetIdentifiers(id){ $.get( 'getCultureIdentifiers.php?cultureID=' + id, function(data){ if (data.length >
I have the following form, and I am dynamically adding more dropdowns (exactly the
I currently have the following code: while not (sqlMailMergeData.Eof) do begin if sqlMailMergeData.FieldByName('Email').AsString <>
Let's say I have the following function (where mVertexShader is an std::shared_ptr< ID3D11VertexShader >
Trying to tidy up scope and avoid possible multiple calls to RegisterWindowMessage. Currently have
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I have a continuous linear programming problem that involves maximizing a linear function over
I'm currently self-studying C for mastering an university project. In that project we have

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.