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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:28:23+00:00 2026-05-14T22:28:23+00:00

I am currently using the built in random number generator. for example nAsp =

  • 0

I am currently using the built in random number generator.

for example

nAsp = randi([512, 768],[1,1]);

512 is the lower bound and 768 is the upper bound, the random number generator chooses a number from between these two values.

What I want is to have two ranges for nAsp but I want one of them to get called 25% of the time and the other 75% of the time. Then gets plugged into he equation. Does anyone have any ideas how to do this or if there is a built in function in matlab already?

for example

nAsp = randi([512, 768],[1,1]); gets called 25% of the time

nAsp = randi([690, 720],[1,1]); gets called 75% of the time

  • 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-14T22:28:24+00:00Added an answer on May 14, 2026 at 10:28 pm

    I assume you mean randomly 25% of the time? Here’s one easy way to do it:

    if (rand(1) >= 0.25) %# 75% chance of falling into this case
        nAsp = randi([690 720], [1 1]);
    else
        nAsp = randi([512 768], [1 1]);
    end
    

    If you know you’re generating N of these, you can do

    idx = rand(N,1);
    nAsp = randi([690 720], [N 1]);
    nAsp(idx < 0.25) = randi([512 768], [sum(idx < 0.25) 1]); %# replace ~25% of the numbers
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using Doctrine's DBAL library for MySQL interfacing and have currently built
I have recently built an iPad app using PhoneGap. Currently it saves the last
Our company website features a random shard generator, built in Flash, which creates a
I'm currently using the built-in methods in Windows Phone and Silverlight to create a
I work on a set of python unit tests that are currently built using
I am currently using OpenCV's built-in patch-based histogram back projection ( cv::calcBackProjectPatch() ) to
I'm currently using two images for a menu that I've built. I was using
I am currently using built in Windows Authentication for my MVC3 web app. It
I am currently using silverlight to build a control for a CRM form. There
We are currently using JDeveloper to build our production EARs. One problem with this

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.