Message Boards Message Boards

0
|
2665 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Range of values except x

Posted 9 years ago

Hi everyone.

So, I'm new to Mathematica so this is probably very straightforward but I just can't do it. What I'm trying to do is to create a table of probabilities but without a specific undefined value to use with the command RandomChoice to select a range of numbers. For instance:

z = RandomChoice[
 Flatten[Table[{y/100}, {y, 
     50}]] -> Range[1, 50], 1]

So far so good. But now, I want out of choices the number 45. In order to do this, I also need to remove the scenario where y=45, right? I can do this, but I don't what to specify the value that is going to be taken out. Also, this is in the function "Do" since I'm running a simulation. Therefore, the process needs to start all over again, with z acquiring new values. Anyone knows how to do this?

Thanks!

POSTED BY: Goncalo Faria
Posted 9 years ago

If within your Do loop you know the index of the value that you want to exclude (and suppose that index is k), then outside of your Do loop you could use

w = Flatten[Table[{y/100}, {y, 50}]]
e = Range[1, 50]

and within the Do loop (which I assume determines the index k in some fashion)

z = RandomChoice[Delete[w, k] -> Delete[e, k], 1]

which just removes that item from both w and e and makes the random selection.

POSTED BY: Jim Baldwin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract