# How send random values to selector every n-times

**URL:** <https://www.ruby-forum.com/t/how-send-random-values-to-selector-every-n-times/233362>\
**Category:** GNU Radio\
**Created:** [December 7, 2014, 11:00pm UTC](https://www.ruby-forum.com/t/how-send-random-values-to-selector-every-n-times/233362 "2014-12-07T23:00:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [December 7, 2014, 11:00pm UTC](https://www.ruby-forum.com/t/how-send-random-values-to-selector-every-n-times/233362/1 "2014-12-07T23:00:54Z")

</div>

Hi everybody,  
I need to “switch” randomly 5 different signal generator via selector  
block  
every [say] 3 seconds…

So , in GRC, I’ve a vector\_source with values coming from  
[random.randint(0, 4) for p in range(0,4)]. This put some random values  
displayed right.

Now how I can scan the vector, a values at time sending this index to  
selector, every n-seconds ???

I’m not with a USRP , simple sound card.

Tnx in advance for any answer!

Victor

---

<div class="post-metadata">

**Author:** ![Vitt\_Benv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/e495f1/32.png) [@Vitt\_Benv](https://www.ruby-forum.com/u/Vitt_Benv)\
**Post date:** [December 8, 2014, 3:12pm UTC](https://www.ruby-forum.com/t/how-send-random-values-to-selector-every-n-times/233362/2 "2014-12-08T15:12:45Z")

</div>

Hi,

Please go through the tutorial [1].

Short version,

1. Use one 5in-1out selector block
2. Use on “Function Probe” block
3. Set the “Poll Rate” based on your delay
4. Generate python file using “Generate flowgraph” button
5. Set your selector’s input index in the function probe

Sample function probe

> > def \_fn\_probe\_probe():  
> > while True:  
> > try:

self.blks2\_selector\_0.set\_input\_index(random.randint(0,4))

> > ```
> > except AttributeError:
> > pass
> > time.sleep(1.0 / (0.3))
> > 
> > ```

6.Run your python code

[1]  
[https://gnuradio.org/redmine/projects/gnuradio/wiki/Guided\_Tutorial\_GNU\_Radio\_in\_Python#315-Modifying-the-GRC-Generated-Python-File](https://gnuradio.org/redmine/projects/gnuradio/wiki/Guided_Tutorial_GNU_Radio_in_Python#315-Modifying-the-GRC-Generated-Python-File)

Sreeraj

---

<div class="post-metadata">

**Author:** ![Vitt\_Benv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/e495f1/32.png) [@Vitt\_Benv](https://www.ruby-forum.com/u/Vitt_Benv)\
**Post date:** [December 8, 2014, 11:17pm UTC](https://www.ruby-forum.com/t/how-send-random-values-to-selector-every-n-times/233362/3 "2014-12-08T23:17:54Z")

</div>

Thanks Sreeraj,

just a quick test without success ☹

I’ve tested the example in the tutorial and it work, so I’ve to read  
carefully the section to understand how put hand on my code.

Next days I’ll be away for my job so next tests maybe done during next  
weekend.

I’ll report results 😉

Byebye,

Victor

2014-12-08 15:11 GMT+01:00 sreeraj r [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
