I in partioning bits of random number in matlab

Click For Summary

Discussion Overview

The discussion revolves around partitioning bits of a random number in MATLAB, specifically how to divide a set of bits into smaller groups. Participants are exploring coding techniques to achieve this, including the use of loops and random number generation functions.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant seeks assistance in partitioning bits into 4 smaller groups from a random number generated in MATLAB.
  • Another participant expresses confusion about the initial request and asks for clarification on the intended outcome.
  • A participant proposes a method to randomly select 8 bits from a set of 40 bits, suggesting the use of a loop to achieve this.
  • There is a suggestion that the partitioning may not be necessary, with an emphasis on randomly selecting indices from the set of bits.
  • Participants discuss the generation of bits as 0s and 1s with equal probability and how to structure the output into 5 sections of 8 bits each.

Areas of Agreement / Disagreement

Participants do not appear to reach a consensus on the necessity of partitioning the bits, with some suggesting it is not relevant while others maintain it is part of the task. The discussion remains unresolved regarding the best approach to implement the partitioning.

Contextual Notes

There are limitations in the clarity of the initial explanation, and participants express uncertainty about the coding approach and the specific requirements for the partitioning task.

absolute76
Messages
21
Reaction score
0
I need help in partioning bits of random number in matlab!

Hey guys,

I really need your help here...What i wanted to do actually is to partition the bits into 4 smaller group..

If anyone of you can give me a basic coding of it or maybe u can check if there anything wrong wit my coding..

Ex: x=80
rand('state',100)
randn('state',200)
a=rand(1,x)>0.5

should i do for loop? should i add this function

Ex: for x=(4:1:4)

a=rand(1,x)>0.5

end

but it will not give me a random number 0f 4 bits..how? anyone can helpp please??
 
Physics news on Phys.org


absolute76 said:
Hey guys,

I really need your help here...What i wanted to do actually is to partition the bits into 4 smaller group..
I don't understand what you're saying.
absolute76 said:
If anyone of you can give me a basic coding of it or maybe u can check if there anything wrong wit my coding..

Ex: x=80
rand('state',100)
randn('state',200)
a=rand(1,x)>0.5

should i do for loop? should i add this function

Ex: for x=(4:1:4)

a=rand(1,x)>0.5

end

but it will not give me a random number 0f 4 bits..how? anyone can helpp please??
Can you tell me in words what you're trying to do? Here is some documentation for the randn function - http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randn.html

and for the rand function - http://www.mathworks.com/access/helpdesk/help/techdoc/ref/rand.html

If you need a loop it should look something like this.
Code:
do i=1:2:9
% some calculation
end
This loop runs 5 times, for i = 1, 3, 5, 7, and 9.
 


Ok, let say i have 40 bits..

My question now is..how do i do 5 partition for the 40 bits (each partition consists of 8 bits)so that everytime i simulate it,it will randomly pick 8 bits from the 40 bits??

but i have to use this code in it:

x=40
rand('state',100);
randn('state',200);

input=rand(1,x)>0.5

do you have any idea??
 
Last edited:


I don't think partitioning the set of bits enters into it. And your explanation is still not very clear. My best guess is that you have 40 bits to choose from, with indexes in the set {0, 1, 2, 3, 4, ..., 38, 39} and you want to pick 8 bits at random.

The following statement will store an integer from 0 through 39 in x. If you do that 8 times, you'll get 8 different values.

x = fix(40 * rand)

This code will put 8 values in an array.
Code:
do i = 1:8
  x(i) = fix(40 * rand)
end
 


Mark44 said:
I don't think partitioning the set of bits enters into it. And your explanation is still not very clear. My best guess is that you have 40 bits to choose from, with indexes in the set {0, 1, 2, 3, 4, ..., 38, 39} and you want to pick 8 bits at random.

The following statement will store an integer from 0 through 39 in x. If you do that 8 times, you'll get 8 different values.

x = fix(40 * rand)

This code will put 8 values in an array.
Code:
do i = 1:8
  x(i) = fix(40 * rand)
end

Ok that's true i have 40 bits now.

and because of :

rand('state',100);
randn('state',200);
a=rand(1,x)>0.5 ...this line will generate 0,1 with equal probility

so my 40 bits just now are being generated as 0 and 1

and through that i want to partition it into 5 section( each of it will consist of 8 bits). The 8 bits will be choose randomly from the output I've given.

Example of evaluate of that selection i have this output:

x =

40


a =

Columns 1 through 14

0 1 1 1 1 1 1 0 0 1 1 1 0 0

Columns 15 through 28

1 0 1 0 0 0 1 1 1 0 1 0 1 1

Columns 29 through 40

1 1 0 0 1 1 1 0 1 0 0 1
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
Replies
3
Views
2K
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K